【发布时间】:2013-11-26 13:01:18
【问题描述】:
我正在尝试替换 html 文档中两个标签之间的文本。我想替换任何没有用 括起来的文本。 我想使用 str_replace 来执行此操作。
php $string = '<html><h1> some text i want to replace</h1><p>some stuff i want to replace </p>';
$text_to_echo = str_replace("Bla","Da",$String);
echo $text_to_echo;
【问题讨论】:
-
我猜你需要
Regex来实现这一点。 -
html 最好通过将其解析为 XML 来处理。有些事情可以用正则表达式来实现,但是str_replace根本不适合这个任务。
-
强制链接到“RegEx 匹配开放标签,XHTML 自包含标签除外”线程:stackoverflow.com/questions/1732348/…
-
我建议你阅读这个 SO 问题stackoverflow.com/questions/8687778/…
标签: php html string str-replace