如何在 PHP 中忽略某些标签并替换文本

发布于 2024-09-05 05:05:27 字数 453 浏览 5 评论 0原文

我有一个变量,就像

$content = "Lorem Ipsum is simply <b>dummy text of the printing</b> and typesetting industry.
 Lorem Ipsum has been the industry's <i>standard dummy text</i> ever since the 1500s 
<string>javascriptFunc();</script>" ;

我使用 str_replace('a', '', $content); 时一样,所有 'a 都被删除了。但

或者除了这个方法之外还有什么方法可以替换文本

请帮忙。

I have a variable like

$content = "Lorem Ipsum is simply <b>dummy text of the printing</b> and typesetting industry.
 Lorem Ipsum has been the industry's <i>standard dummy text</i> ever since the 1500s 
<string>javascriptFunc();</script>" ;

when i use str_replace('a', '', $content); all the 'a's get removed. But the 'a's within the <script> tag should not be removed.

or is there any way to replace text other than this method

Please help .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

司马昭之心 2024-09-12 05:05:27

使用 HTML DOM 解析器 获取标签内的文本,然后在结果。

Use a HTML DOM parser to get the text within the tags, and then run your str_replace() function on the result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文