Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

Escape UTF-8 Unicode Characters for XML

Dawn Rossi, 12-19-2008
This function will allow you to use Unicode data with XML

XML [[CDATA]] doesn't allow Unicode characters unless they are escaped


function escapedata($data)

   
$position=0
   
$length=strlen($data);
   
$escapeddata='';
    for(;
$position<$length;)
    {
     
$character=substr($data,$position,1);
     
$code=Ord($character);   
      switch(
$code)
      {   
        case
10:
        case
13:   
        case
9:   
        break;     
 
        default:
        if(
$code<32)
           
$character=('&#'.strval($code).';');
        break; 
      }
     
$escapeddata.=$character;
     
$position++;
    }
    return
$escapeddata;
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions