Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Jeremy Cook's Blog:
Recursive Closures in PHP 5.3
Aug 13, 2010 @ 18:07:59

In this recent post from Jeremy Cook he take a look at an interesting use of closures in PHP - using them recursively to strip slashes off a string.

One thing all of my projects have in them is code to remove the quotes added so I can handle appropriate escaping myself. This [example from the PHP manual] works perfectly but it does end up creating a function in the global namespace which is only called once. A perfect job for a closure.

He includes an example of how to do it with a normal, globally-defined function and how to handle it with a closure (that calls itself via an array_map) - a closure contained inside of itself with the string variable passed in by reference. Then, when it's done stripping out slashes, the closure is dropped and nothing new is added to the global namespace.

tagged: closure recursive stripslashes tutorial

Link:

Arul Pradad's Blog:
Saving XML from Flash, using PHP
Jun 21, 2006 @ 23:39:53

On Arul Pradad's blog today, there's a quick post talking about a simple way to save the XML coming from a Flash file with PHP.

I was trying to create a XML file on the server, using PHP. The XML string was being sent from Flash, by adding the same as a property to a LoadVars obj. ( Since I had to send few other data items as well - other than the XML string, I couldn't use Flash's XML.sendAndLoad method.

He shows the code that was giving him troubles and traces the path he took to discover the ultimate problem with the XML - the quotes in the file were being escaped, resulting in PHP's inability to parse it correctly. A simple call to stripslashes solved that, and the app works just fine.

tagged: save xml flash parse stripslashes save xml flash parse stripslashes

Link:

Arul Pradad's Blog:
Saving XML from Flash, using PHP
Jun 21, 2006 @ 23:39:53

On Arul Pradad's blog today, there's a quick post talking about a simple way to save the XML coming from a Flash file with PHP.

I was trying to create a XML file on the server, using PHP. The XML string was being sent from Flash, by adding the same as a property to a LoadVars obj. ( Since I had to send few other data items as well - other than the XML string, I couldn't use Flash's XML.sendAndLoad method.

He shows the code that was giving him troubles and traces the path he took to discover the ultimate problem with the XML - the quotes in the file were being escaped, resulting in PHP's inability to parse it correctly. A simple call to stripslashes solved that, and the app works just fine.

tagged: save xml flash parse stripslashes save xml flash parse stripslashes

Link:


Trending Topics: