Note that there are some explanatory texts on larger screens.

plurals
  1. POphp preg_replace € sign with "euro"
    primarykey
    data
    text
    <p>I would like to replace the € sign in $XML_COMMENT with "euros" before adding to a xml file.</p> <p>The € sign not being a utf-8 character I get and error message from simplexml</p> <pre><code>Warning: SimpleXMLElement::addAttribute(): string is not in UTF-8 in ... Warning: SimpleXMLElement::asXML(): output conversion failed due to conv error, bytes 0x82 0x26 0x61 0x6D in .... </code></pre> <p>The euro sign appears in the MySQL (utf-8) database as '€'</p> <p>But appears correctly in the textarea on the webpage.</p> <p>I tried to use these different str_replace </p> <pre><code>$XML_COMMENT=str_replace('€','euros',$XML_COMMENT) $XML_COMMENT=str_replace('€','euros',$XML_COMMENT) $XML_COMMENT=str_replace(chr(128),'euros',$XML_COMMENT) $XML_COMMENT=str_replace(chr(0xE2).chr(0×82).chr(0xAC),'euros',$XML_COMMENT) $XML_COMMENT=str_replace(chr(0x82).chr(0x26).chr(0x61).chr(0x6D),'euros',$XML_COMMENT) </code></pre> <p>without success</p> <p>FYI: I'm using utf-8 everywhere (MySQL, Web Page and XML)</p> <p>Here's my code</p> <pre><code>// ? : $XML_COMMENT= "bla bla bla € bla bla bla"; // ? : $XML_COMMENT= "bla bla bla € bla bla bla"; // expected : $XML_COMMENT= "bla bla bla euros bla bla bla"; $ProductLog_XML = simplexml_load_file($file); $ProductUpdate = $ProductLog_XML-&gt;order-&gt;product-&gt;addChild('update'); $ProductUpdate-&gt;addAttribute('comment',$XML_COMMENT); $fp=fopen(file, "w"); fwrite($fp, $ProductLog_XML-&gt;asXML()); fclose($fp); </code></pre> <p>Is there any alternative using regex / preg_replace ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload