sanitize textarea DG - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of sanitize textarea DG.php
- <?php
- function db_escape($text){
- //for example mysqli_real_escape_string
- return($text);
- }
- function br2nl($text){
- return preg_replace('/\<\/br(\s*)?\/?\>/i', "\n", $text);
- }
- function _toUTF8($m){
- if(function_exists('mb_convert_encoding')){
- return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
- }else{
- return $m[1];
- }
- }
- function entToUTF8($input){
- return preg_replace_callback('/(&#[0-9]+;)/', '_toUTF8', $input);
- }
- $string = " <HACKING> òàèìù !(!«´««“‘\\\\\\\\{{{{»”’«“‘»{}}\n\n{:,.lò </HACKING> ";
- $string = trim($string);//so we are sure it is whitespace free at both ends
- //preserve newline for textarea answers
- $string = str_replace("\n","[NEWLINE]", $string);
- $out = entToUTF8(br2nl(db_escape($string)));
- //now replace the placeholder with the original newline
- $out = str_replace("[NEWLINE]", "\n", $out);
- print "input=\t".$out;
- print ("\noutput=\t".$out);
- ?>
File Description
- sanitize textarea DG
- PHP Code
- 15 Dec-2020
- 1017 Bytes
You can Share it:
Latest PHP Pastes