<?php if(!Empty($_POST)) { $_POST = stripslashes($_POST); //how to stripslashes all the variables in $_POST? print_r($_POST); } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf8"> </head> <body> <form action="<?=$PHP_SELF?>" method="post"> <table border="0" width="300" cellspacing="0" cellpading="0"> <tr> <td>text1:</td> <td><input type="text" name="txt1"></td> </tr> <tr> <td>text2:</td> <td><input type="text" name="txt2"></td> </tr> <tr><td colSpan="2"><input type="submit" value="Submit"></td></tr> </table> </form> </body> </html>
foreach($_POST as $key => $value) { $_POST[$key] = stripslashes($value); }
DO THIS: foreach($_POST as $key => $va) { $$key = stripslashes($val); }
this will change $_POST vars to like simple $vars
thanks drew010 🙂
You could simplify drew010's code by using [man]array_map[/man]:
$_POST = array_map('stripslashes', $_POST);