Unexpected behavior from $_POST string variable in PHP -


i working on simple accent stripping function on php

$your_data = $_post["input"];  function stripchar($str) {                   $char = array(                       'a'=>'á|à|ặ|â',                      );                  foreach($char $stripped_char => $original_char){                         $str = preg_replace("/($original_char)/i", $stripped_char, $str);             }             return $str;             }  echo stripchar($your_data); 

it worked if try echo accented characters (á à ặ â), of return intended characters (a a a).

however, when put use - taking string variable $string = $_post["input"] html file, inputted user, function did not change accented characters @ all.

the html code:

<!doctype html> <html> <body>   <div class="inputbox">         <form action="action_page.php" method="post">                 <textarea type="text" name="input" style="width: 100%; height: 200px;"></textarea>                 <input type="submit" name="action" value="strip" class="button_form">         </form>    </div> </body> </html> 

i still quite confused. tried var_dump $string variable , showed string variable. tested function takes accented string in script again, , still worked. not string input field!

try instead:

function stripaccents($stripaccents){   return strtr($stripaccents,'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ','aaaaaceeeeiiiinooooouuuuyyaaaaaceeeeiiiinooooouuuuy'); } 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -