str_replace() 无法正常工作
str_replace() not working properly
早上好,
我目前正在尝试替换 xml 文档中的一些字符串,其中一些可以正常工作,但另一些则不能,我无法弄清楚为什么...这个问题会出现吗事实上 xml 是使用 Microsoft Word 编写的 ?
这是我的 PhP 代码:
<?php
$document = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/../wwwPublic/vehicule_ci/assets/res/annulation.xml");
$document = str_replace('@ville@', "test_ville", $document);
$document = str_replace('@date@', date('d/m/Y'), $document);
$document = str_replace('@emetteur@', "test_emetteur", $document);
$handle = fopen(utf8_decode($documentPath), "w");
fwrite($handle, $document);
fclose($handle);
echo $document;
?>
这是输出:
test_ville le 20/04/2017Ref Client : @emetteur@N° Voucher :ÉmetteurDestinataireNom :@emetteur@
如您所见,"ville" 和 "date" 被正确替换,但 "emetteur" 不是...,如果有人有想法,我'我会接受的。
谢谢
很有可能是因为文档是用word写的。我以前也遇到过这样的错误。也许您需要使用 iconv 函数转换文档。
早上好,
我目前正在尝试替换 xml 文档中的一些字符串,其中一些可以正常工作,但另一些则不能,我无法弄清楚为什么...这个问题会出现吗事实上 xml 是使用 Microsoft Word 编写的 ?
这是我的 PhP 代码:
<?php
$document = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/../wwwPublic/vehicule_ci/assets/res/annulation.xml");
$document = str_replace('@ville@', "test_ville", $document);
$document = str_replace('@date@', date('d/m/Y'), $document);
$document = str_replace('@emetteur@', "test_emetteur", $document);
$handle = fopen(utf8_decode($documentPath), "w");
fwrite($handle, $document);
fclose($handle);
echo $document;
?>
这是输出:
test_ville le 20/04/2017Ref Client : @emetteur@N° Voucher :ÉmetteurDestinataireNom :@emetteur@
如您所见,"ville" 和 "date" 被正确替换,但 "emetteur" 不是...,如果有人有想法,我'我会接受的。
谢谢
很有可能是因为文档是用word写的。我以前也遇到过这样的错误。也许您需要使用 iconv 函数转换文档。