我想用 html 代码替换图像,这必须是 php 函数的输出。
每当在 html 文档中找到图像标签时,都应将其传递给 php 函数并替换为 html 字符串。
我的期望如下。
index.htm 文件包含
hello
句子延续。
这个 image.jpg 被传递给 php 函数,例如
convert_pic('image.jpg');
所以index.htm的输出是
hello
....
句子延续。
其中 ....
是 php 函数 convert_pic('image.jpg');
的输出,
因此 < img src="image.jpg" />
将替换为
如何做到这一点,或者有其他可能性来实现这一目标?
I want to replace a image with html code, that must be the output of a php function.
whenever a image tag is found in an html document, it should be passed to a php function and replaced with a html strings.
my expectation is like below.
index.htm file contains
hello <img src="image.jpg" />
sentence continuation.
this image.jpg is passed to php function like
convert_pic('image.jpg');
so the output of index.htm is
hello <div>....</div>
sentence continuation.
where <div>....</div>
is the out put of php function convert_pic('image.jpg');
so <img src="image.jpg" />
is to be replace by <?php convert_pic('image.jpg');
how it can be done, or any other possibility to attain this?
发布评论
评论(1)
通过 DOM 扩展,您可以使用 XPath 查找所有 img 标签,然后替换它们
另请参阅:
例如
打印
With the DOM extension you can use XPath to find all img tags and then replace them
see also:
e.g
prints