Jump to content

htmlentities and € symbol


prometheos

Recommended Posts

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("€", "&#8364;",$delivery);

But that still ends up the same way...  :wtf:

 

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

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?

Ok thanks :)

i just tried that and got the same annoying error when i tried to display the xml  :'( :wtf::shrug:

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?

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.