PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
 

Code Snippets

  

PHP Source Code



Decode URL with Unicode characters

This is a snippet to decode a URL that has Unicode characters in it

Submitted By: PsychoCoder
Actions:
Rating:
Views: 7,653

Language: PHP

Last Modified: March 9, 2008
Instructions: The urldecode function in PHP does a pretty good job decoding URL's. One shortcoming is with URL's that contain Unicode characters such as %0. This can cause trouble, especially when working with fixed length string.

Just pass the function your URL

Snippet


  1. //Function to decode URL's that contain Unicode characters
  2. function unicode_urldecode($url)
  3. {
  4.   //split the URL into an array
  5.   $url_array = split ("%",$url);
  6.   //Make sure we have an array
  7.   if (is_array($url_array))
  8.   {
  9.     //Loop while the key/value pair of the array
  10.     //match our list items
  11.     while (list ($k,$v) = each ($url_array))
  12.     {
  13.        //use base_convert to convert each character
  14.        $ascii = base_convert ($v,16,10);
  15.        $ret .= chr ($ascii);
  16.     }
  17.  }
  18.  //return the decoded URL
  19.  return ("$ret");
  20. }

Copy & Paste


Comments

SubCon 2008-03-25 20:41:11

Thanks a lot man. This function saved me time going into the issue.. So thanks again!


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.