View Single Post
Old 02-21-2013, 11:26 AM   PM User | #1
mr curious
New Coder

 
Join Date: Jan 2011
Posts: 55
Thanks: 7
Thanked 0 Times in 0 Posts
mr curious is an unknown quantity at this point
Can't decode special characters from xml

Hi all,

I've got this script which converts data from a mysql database to an xml object using the DOM and printing it out. Everything works fine, however some of the text contains ampersands (&) which gets printed as '&amp'

here's the script:
PHP Code:
<? 
function getdata($type

    
$mysqHost "xxx"
    
$mysqlUsr "xxx"
    
$mysqlPass "xxx"
     
     
    
$conn mysql_connect($mysqHost,$mysqlUsr,$mysqlPass); 
     
    
mysql_select_db("xxx") ; 

    
$sql = ("SELECT * FROM `$type`;"); 
    
$result =  mysql_query($sql); 
    
$doc = new DomDocument('1.0'); 
    
$type $str str_replace(' ','',$type); 

    
$root $doc->createElement($type.'List'); 
        
$root $doc->appendChild($root);   
    while(
$row mysql_fetch_assoc($result)) 
    { 
         
       
$company$doc->createElement($type); 
       
$company $root->appendChild($company);     
       foreach(
$row as $fieldname => $fieldvalue
       { 
            if(
$fieldname !='id'
            { 
            
$child $doc->createElement($fieldname); 
            
$child $company->appendChild($child); 
            
//add data to the new element 
            
$value $doc->createTextNode($fieldvalue); 
            
$value $child->appendChild($value); 
            } 
             
        } 
    } 
    
$str $doc->saveXML(); 

    print 
$str



$type $_REQUEST['type']; 
        
getdata($type);     

if(
$conn){ mysql_close($conn); } 
?>
I've tried to decode $fieldValue using html_entity_decode, but it doesn't work. I really don't know how to fix this. Any help would be greatly appreciated.

Thanks

Last edited by mr curious; 02-21-2013 at 11:27 AM.. Reason: unneeded code
mr curious is offline   Reply With Quote