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.



Your result can be seen below.

Result of php executing





Full code of sanitize textarea DG.php

  1. <?php
  2. function db_escape($text){
  3.     //for example mysqli_real_escape_string
  4.     return($text);
  5. }
  6.         function br2nl($text){
  7.                 return  preg_replace('/\<\/br(\s*)?\/?\>/i', "\n", $text);
  8.         }
  9.         function _toUTF8($m){
  10.                 if(function_exists('mb_convert_encoding')){
  11.                         return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
  12.                 }else{
  13.                         return $m[1];
  14.                 }
  15.         }
  16.         function entToUTF8($input){
  17.                 return preg_replace_callback('/(&#[0-9]+;)/', '_toUTF8', $input);
  18.         }
  19.        
  20.         $string="<HACKING> òàèìù !(!«´««“‘\\\\\\\\{{{{»”’«“‘»{}}{:,.lò </HACKING>";
  21.         $_POST['ta1']=$string;
  22.         $_POST['txt1']=$string;
  23.        
  24. //     $out = entToUTF8(br2nl(db_escape($string)));
  25. //     print "input=\t".$out;
  26. //     print ("\noutput=\t".$out);
  27.  
  28. ?>
  29. <!doctype html>
  30. <html>
  31. <head>
  32. <meta charset="utf-8">
  33. <title>Filter test</title>
  34. </head>
  35.  
  36. <body>
  37.    
  38. <form action="" method="post">
  39.     <p>
  40.         <textarea name="ta1" cols="30" rows="10"><?php echo $_POST['ta1']; ?></textarea>
  41.     </p>
  42.     <p>
  43.         <input type="text" name="txt1" size="30" value="<?php echo $_POST['txt1']; ?>" />
  44.     </p>
  45.     <p>
  46.         <input type="submit" />   
  47.     </p>
  48.     </form>
  49.  
  50. </body>
  51.    
  52. </html>
File Description
  • sanitize textarea DG
  • PHP Code
  • 15 Dec-2020
  • 1.17 Kb
You can Share it: