Tools, FAQ, Tutorials:
Removing Slashes on Submitted Input Values in PHP
How To Remove Slashes on Submitted Input Values in PHP?
✍: FYIcenter.com
By default, when input values are submitted to the PHP engine, it will add slashes to protect single quotes and double quotes. You should remove those slashes to get the original values by applying the stripslashes() function. Note that PHP engine will add slashes if the magic_quotes_gpc switch is turned off. The PHP script below is an enhanced version of processing_forms.php with slashes removed when magic_quotes_gpc is turned on:
<?php print("<html><pre>"); $count = count($_REQUEST); print("Number of values: $count\n"); foreach ($_REQUEST as $key=>$value) { if (is_array($value)) { print(" $key is an array\n"); for ($i = 0; $i < count($value); $i++) { $sub_value = $value[$i]; if (get_magic_quotes_gpc()) { $sub_value = stripslashes($sub_value); } print(" ".$key."[".$i."] = ".$sub_value."\n"); } } else { if (get_magic_quotes_gpc()) { $value = stripslashes($value); } print(" $key = $value\n"); } } print("</pre></html>\n"); ?>
Now if you submit the same data again as in the previous exercise, you will get the original values as:
Number of values: 2 name = Alan comment = I want to say: "It's a good site! :->"
⇒ Supporting Multiple Submit Buttons in PHP
2022-12-14, 3741🔥, 1💬
Popular Posts:
How To Submit Values without Using a Form in PHP? If you know the values you want to submit, you can...
Where Is the Submitted Form Data Stored in PHP? When a user submit a form on your Web server, user e...
Where to get a real Atom XML example? You can follow this tutorial to get a real Atom XML example: 1...
How To Open Standard Output as a File Handle in PHP? If you want to open the standard output as a fi...
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...