Jump to content

[SOLVED] XML Special Characters


ssj16

Recommended Posts

Hi Guys,

 

I've been looking all over to try and figure this out but I am new to dealing with XML in PHP.

 

I have successfully read my XML file and echoed my data into a browser by returning a String using this function:

 

function getTitle($filePath){

$xmlDoc = new DOMDocument();

$xmlDoc->load($filePath . "\structure.xml" );

$searchNode = $xmlDoc->getElementsByTagName( "course" );

 

foreach( $searchNode as $searchNode )

{

$valueID = $searchNode->getAttribute('title');

        return $valueID;

}

 

 

}

 

But say if the value of my attribute had special characters in it such as:

 

<structure>

<course title="LOREM® IPSUM™">

        </course>

</structure>

 

The output in the browser would be: LOREM® IPSUM™

 

If i am missing something or parsing the data wrong any help would be of assistance.

 

Thanks  Alot

Link to comment
https://forums.phpfreaks.com/topic/144702-solved-xml-special-characters/
Share on other sites

Off the top of my head, it's because by default PHP will set the character set of the page to be 8859-1.  So you might try this at the top and see if that takes care of it:

 

header('Content-type: text/html; charset=UTF-8') ;

THANKS ALOT GIZMOLA  :)

 

I thought about this but I thought it needed to be done on the XML side, since our XML pages do not have the encoding at the top, but now that I think about it, it definitely makes more sense that it would be in the PHP page since it's being processed.  Unfortunately, I never put the encoding at the top (laziness), but now I truly realize the importance of the encoding at the top of my html/php pages.

 

Once again, thank you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.