我想在添加到xml文件之前用“欧元”替换$ XML_COMMENT中的欧元符号。php preg_replace欧元符号
的€符号不是一个UTF-8字符我得到与错误消息从simplexml的
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 ....
欧元符号出现在MySQL(UTF-8)数据库为 'â,¬'
但是在网页的textarea上正确显示。
我试图用这些不同的str_replace函数
$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)
没有成功
FYI:我使用UTF-8无处不在(MySQL的,网页和XML)
这里是我的代码
// ? : $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->order->product->addChild('update');
$ProductUpdate->addAttribute('comment',$XML_COMMENT);
$fp=fopen(file, "w");
fwrite($fp, $ProductLog_XML->asXML());
fclose($fp);
是否有任何替代使用正则表达式/ preg_replace?
'我在使用utf-8无处不在.'不,你不是。很可能您的编辑器配置错误,并使用其他编码。 – phihag
我用utf-8检查过它yes dosent使用utf-8编码,当我删除指定我的字符集的元标记时它正常工作!!!!! ----无法理解:(这是什么类型的字符? –
@phphag是什么让你这么说?我认为编辑器与我的问题没有任何关系,因为$ XML_COMMENT来自utf-8由utf-8网页提供的MySQL表 – baptme