PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
if i have a string like this "asdadçâsadaãoç" in $row['CLOC'], and then open the .xml file it gives me a message saying that i have a invalid caractere, can anyone tell me how to avoid this issue ?
Also, stick with the utf one, but check so that your editor is saving it correct. I use UltraEdit myself and that has quite some settings for dealing with UTF saving (with or without BOM, UTF-8 or 16 aso aso).
i've changed from $doc = new DOMDocument('1.0', 'utf-8'); to $doc = new DOMDocument('1.0', 'windows-1252'); and $doc = new DOMDocument('1.0', 'ISO-8859-1'); without solving this issue. i've also used header("Content-type: text/xml; charset=utf-8");
any ideas ?
one more thing how can i add this xml namespace (xmlns) attribute to a element ( xmlns:namespace-prefix="namespaceURI" ) ?
i've tried that function but instead of "ã" i get a empty square, maybe because of DOM ?
can you tell me if there is a better way to create a xml file ?
i've found this function htmlentities(), will test this as soon as possible and reply telling if it work.
//Creates XML string and XML document using the DOM
$dom = new DomDocument('1.0');
//add root - <links>
$links = $dom->appendChild($dom->createElement('links'));
//add Dummy Node
$linkNode = $links->appendChild($dom->createElement('link'));
$linkNode->appendChild($dom->createTextNode('Dummy'));
$linkNode->setAttribute("url", "www.parsiTech.com");
//generate xml set the format Output attribute of domDocument to true
$dom->formatOutput = true;
// save XML as string or file put string in data
$data = $dom->saveXML();
$dom->save($file); // save as file
i have used this for Arabic,Russian,Persian characters which are Unicode
and one thing you should not forget is it is not important what the editors show you after creating the file it is important that when you open the spesified xml file through the php code it would work properly