prometheos Posted March 24, 2010 Share Posted March 24, 2010 hi, i have a html form and one of the fields has to take in a currency symbol. so for example the € symbol in say the 'delivery' field.I then have to put this into an xml field but everytime i try, the xml file gives me a parsing error for undefined entity :-\ Heres a sample of what i have: $descriptionInput = $_POST['description']; $itemInput = $_POST['item_name']; $quantityInput = $_POST['quantity']; $deliveryCityInput = $_POST['deliveryCity']; $deliveryInput = $_POST['delivery']; $picSourceInput = $_POST['picSource']; $description = htmlentities($descriptionInput); $item_n = htmlentities($itemInput); $quantity = htmlentities($quantityInput); $deliveryCity = htmlentities($deliveryCityInput); $delivery = htmlentities($deliveryInput); $picSource = htmlentities($picSourceInput); $filename = "./xml_files/".$user_id.".xml"; $file = fopen ($filename, "r"); if (!$file){ $xml = simplexml_load_file(filename); $xmltext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<items></items>"; $items = simplexml_load_string($xmltext); $item = $items->addChild("item"); $item->addAttribute("quantity", $quantity); $item->addChild("itemSource",$source); $item->addChild("itemName",$item_n); $item->addChild("description", $description); $item->addChild("deliveryCity", $deliveryCity); $item->addChild("delivery", $delivery); It's been annoying me for awhile. i've tried str_replace on the $delivery string before its added to the xml with str_replace("€", "€",$delivery); But that still ends up the same way... Does anyone know how to get around this annoying error :'( Please help. any help is great Thanks Link to comment https://forums.phpfreaks.com/topic/196406-htmlentities-and-%E2%82%AC-symbol/ Share on other sites More sharing options...
o3d Posted March 24, 2010 Share Posted March 24, 2010 In your xml output use the CDATA method: <xmltag1> <![CDATA[ put your funny characters in here ]]> </xmltag1> Link to comment https://forums.phpfreaks.com/topic/196406-htmlentities-and-%E2%82%AC-symbol/#findComment-1031237 Share on other sites More sharing options...
prometheos Posted March 24, 2010 Author Share Posted March 24, 2010 In your xml output use the CDATA method: <xmltag1> <![CDATA[ put your funny characters in here ]]> </xmltag1> Hi thanks for the quick reply. how do you mean? where specifically in my xml output? would it b like : $item->addChild("delivery", <![CDATA[$delivery]]>); and would that not ignore what text is typed in there? Link to comment https://forums.phpfreaks.com/topic/196406-htmlentities-and-%E2%82%AC-symbol/#findComment-1031251 Share on other sites More sharing options...
o3d Posted March 24, 2010 Share Posted March 24, 2010 Try this: $item->addChild("delivery", "<![CDATA[{$delivery}]]>"); Remember according to php CDATA (and its tags) are just text. The xml engine will interpret that as special data. Link to comment https://forums.phpfreaks.com/topic/196406-htmlentities-and-%E2%82%AC-symbol/#findComment-1031255 Share on other sites More sharing options...
prometheos Posted March 24, 2010 Author Share Posted March 24, 2010 Ok thanks i just tried that and got the same annoying error when i tried to display the xml :'( parsing error: undefined entity heres the part it highlights '<delivery><![CDATA[â¬]]></delivery>' its the 'â¬' part thats the problem..its just not understanding the € symbol... i took out the str_replace...shud i put it back in? Link to comment https://forums.phpfreaks.com/topic/196406-htmlentities-and-%E2%82%AC-symbol/#findComment-1031261 Share on other sites More sharing options...
o3d Posted March 24, 2010 Share Posted March 24, 2010 After some googling it seems that you might need to use the following for the euro sign: "€" You don't need CDATA tags. $item->addChild("delivery", "€"); http://www.oxygenxml.com/archives/xsl-list/200110/msg00194.html Link to comment https://forums.phpfreaks.com/topic/196406-htmlentities-and-%E2%82%AC-symbol/#findComment-1031285 Share on other sites More sharing options...
prometheos Posted March 24, 2010 Author Share Posted March 24, 2010 hey thanks, i solved it..i just had to use an encoding that had the € symbol in it $delivery = htmlspecialchars($deliveryInput, null , 'ISO-8859-15'); thanks for the help:) Link to comment https://forums.phpfreaks.com/topic/196406-htmlentities-and-%E2%82%AC-symbol/#findComment-1031289 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.