请告诉我如何在PHP中进行查找和替换。
我需要找到 Entry="OK"> 并在 xml 文件中替换为 OK。
我尝试了str_replace但由于其中的 = 和 "> 而感到困惑。
尽管我不确定您正在工作的环境,但我认为这里有一个 php 示例,它可以满足您的需求:
<html>
<?php
$teststr = "Entry='"OK'"";
print $teststr . "<br>";
$newanswer = str_replace($teststr, "Entry=OK", $teststr);
print $newanswer . "<br>";
?>
</html>
试试这种方式
str_replace('Entry="OK"','OK',$var);
您可以使用它str_replace工作
$r = 'Entry="OK" tyyuu hhh';
echo str_replace($r,'Entry="OK"','OK');
如果发现任何错误,则使用带有相应模式的preg_replace