替换 HTML 文本中的所有图像 src 标签 [英] replacing all image src tags in HTML text

查看:65
本文介绍了替换 HTML 文本中的所有图像 src 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个简单的 php 脚本,以从 html 文本中的所有图像中查找所有 src 属性,然后在进行一些条件更改后将所有找到的 src 替换为一些文本.

I'm trying to make a simple php script to find all src attributes from all images in a html text and then replace all found srcs with some text after making some conditional changes.

像这样:

@preg_match_all('/<img\s src="([a-zA-Z0-9\.;:\/\?&=_|\r|\n]{1,})"/isxmU', $body, $images);

现在我已经把所有的 srcs 都放到了 $images 变量中,现在我做了:

now i've all srcs into the $images variable, now i make:

foreach ($images as $img) {
    ..my changes here..
}

现在...如何将更改后的 srcs 再次恢复到 $body 变量??

and now... how can i restore the changed srcs to the $body variable again??

非常感谢,

推荐答案

改用 HTML DOM 解析器,更易于使用和维护 http://simplehtmldom.sourceforge.net/

Use a HTML DOM parser instead, much easier to use and maintain http://simplehtmldom.sourceforge.net/

这篇关于替换 HTML 文本中的所有图像 src 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆