PHP Function: URLDecode All Properties of an Object

April 12th, 2008 · No Comments

I haven’t had a whole lot to blog about lately as I have been stuck doing some Java work that won’t ever really see the light of day (as far as the to the public), so I decided to start posting some of my commonly used PHP functions. I use this function urldecodeObject() along with the mysql_fetch_object() when I’m fetching urlencoded data from a mysql database. This makes it easier than typing urldecode($obj_name->property) every time I need to access/output a property.

  1. function urldecodeObject($obj)
  2. {
  3.     foreach($obj as $key=>$prop)
  4.     {
  5.           $obj->$key = urldecode($prop);
  6.     }
  7.     return $obj;
  8. }

Tags: PHP