$url = "http://www.timeschina.com/";
$pattern = "/<img\s+?(.+)src=(\"|\')??([^\"\'[:space:]]+?)(\"|\')??([^>]*?)>/iU";
$contents = '<img src="images/a.gif" width="12" height="23">';
echo htmlspecialchars(preg_replace($pattern, "<img \\1 src=\"".$url."\\3\"\\5>", $contents));$contents = '<img width="12" height="23" src="images/a.gif">';
echo htmlspecialchars(preg_replace($pattern, "<img \\1 src=\"".$url."\\3\"\\5>", $contents));$contents = '<img src="images/a.gif">';
echo htmlspecialchars(preg_replace($pattern, "<img \\1 src=\"".$url."\\3\"\\5>", $contents));
$pattern = "/<img\s+?(.+)src=(\"|\')??([^\"\'[:space:]]+?)(\"|\')??([^>]*?)>/iU";
$contents = '<img src="images/a.gif" width="12" height="23">';
echo htmlspecialchars(preg_replace($pattern, "<img \\1 src=\"".$url."\\3\"\\5>", $contents));$contents = '<img width="12" height="23" src="images/a.gif">';
echo htmlspecialchars(preg_replace($pattern, "<img \\1 src=\"".$url."\\3\"\\5>", $contents));$contents = '<img src="images/a.gif">';
echo htmlspecialchars(preg_replace($pattern, "<img \\1 src=\"".$url."\\3\"\\5>", $contents));
解决方案 »
- php下载文件为空是怎么回事
- php调用java中的jdbc
- 如何做链接的点击量统计?
- PHP 问题请教
- PHP怎样快速入门(基础足够扎实)
- 至急~~~~ 关于PHP中INI文件读取的问题
- Fatal error: Cannot re-assign $this in D:\php\function.php on line 40 这个解决方法,知道的请进
- 高手帮忙,形如select '' as field1 ....union select field11 as field1中 ''产生的问题
- 一个小问题
- tp5中sql语句分组的问题
- 菜鸟问题,请帮助!
- winXP下如何安装apache2.0.43和PHP4.2.3
參攷
http://expert.csdn.net/Expert/TopicView1.asp?id=1267960
哈哈。
{
$contents = implode("", file($file));
$pattern = "/<img\s+?(.+)src=(\"|\')??([^\"\'[:space:]]+?)(\"|\')??([^>]*?)>/iU";
echo preg_replace($pattern, "<img \\1 src=\"".$url."\\3\"\\5>", $contents);
$fp = fopen($file, "w");
fwrite($fp, $contents);
fclose($fp);
}然后循环读取一个目录调用这个函数即可。
function replace($file, $url = "http://www.timeschina.com/")
{
$contents = implode("", file($file));
$pattern = "/<img\s+?(.+)src=(\"|\')??([^\"\'[:space:]]+?)(\"|\')??([^>]*?)>/iU";
preg_replace($pattern, "<img \\1 src=\"".$url."\\3\"\\5>", $contents);
$fp = fopen($file, "w");
fwrite($fp, $contents);
fclose($fp);
}
function replace($file, $url = "http://www.timeschina.com/")
{
$contents = implode("", file($file));
$pattern = "/<img\s+?(.+)src=(\"|\')??([^\"\'[:space:]]+?)(\"|\')??([^>]*?)>/iU";
$result = preg_replace($pattern, "<img \\1 src=\"".$url."\\3\"\\5>", $contents);
$fp = fopen($file, "w");
fwrite($fp, $result);
fclose($fp);
}
该死的CSDN,明明没有超过连续3个回复,却报错,真是的。