【发布时间】:2014-04-07 06:09:49
【问题描述】:
我尝试用完整的图像 url 替换所有不包含完整 url 的 img src
这样的例子
<?php
$html_str = "<html>
<body>
Hi, this is the first image
<img src='image/example.jpg' />
this is the second image
<img src='http://sciencelakes.com/data_images/out/14/8812836-green-light-abstract.jpg' />
and this is the last image
<img src='image/last.png' />
</body>
</html>";
?>
当替换变成这样的时候
<?php
$html_str = "<html>
<body>
Hi, this is the first image
<img src='http://example.com/image/example.jpg' />
this is the second image
<img src='http://sciencelakes.com/data_images/out/14/8812836-green-light-abstract.jpg' />
and this is the last image
<img src='http://example.com/image/last.png' />
</body>
</html>";
?>
那么如何检查每个不是完整链接的img src并替换它? ($html_str 是基于 mysql 的动态)
请给我一些解决这个问题的方法
谢谢
【问题讨论】:
标签: php mysql image preg-replace