SPLIB: strip_quotes.php

August 1, 2004 at 3:41 pm Leave a comment

Fairly early on in The PHP Anthology by Harry Fuecks, he suggests that Magic Quotes is a problem that all PHP developers has to deal with. Essentially, you must code with the idea that it is enabled, or that it is disabled… If you code as if it is enabled, you’ll run into issues when your app is running on a server that has it disabled. On the other hand, writing your application as if it is disabled will be an issue if it is enabled… Quite the quandry..

Harry’s answer? He includes a piece of code in SPLIB designed to detect if Magic Quotes is enabled, and if so, neutralize it’s effect, so it is as if it is disabled… This way, all your code can be written with the idea that Magic Quotes is off…

Good answer, I say, but I’ve ran into an issue… My test server has Magic Quotes enabled, so strip_quotes.php is active… When I include this piece of code in a script which receives an array of data from the remote web browser, the data gets basically lost… The variable is there, but it is a string variable, containing the word “Array”… I believe the specific failure is with the array_map function, which is what does the brunt of the work in strip_quotes.php.

I solved this problem with the array_map_deep function, which I found in the user notes section on php.net. Basically, it does the same thing as array_map, but it does so in a recursive fashion to any arrays it hits inside the passed array… I also posted my problem, and later my solution on the SitePoint forums. With any luck, this will be a standard part of SPLIB in the future.


Entry filed under: PHP.

Optimization FAQ is coming along nicely

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


August 2004
« Jul   Sep »

Most Recent Posts

%d bloggers like this: