我正在请求这样的网站的源代码:
<? $txt = file_get_contents('http://stats.pingdom.com/qmwwuwoz2b71/522741'); echo $txt; ?>
我想用绝对的替换相关链接!基本上,
<img src="/images/legend_15s.png"/> and <img src='/images/legend_15s.png'/>
应该被替换
<img src="http://domain.com/images/legend_15s.png"/>
和
<img src='http://domain.com/images/legend_15s.png'/>
分别.我怎样才能做到这一点?
此代码仅替换链接和图像:
<? $txt = file_get_contents('http://stats.pingdom.com/qmwwuwoz2b71/522741'); $txt = str_replace(array('href="','src="'),array('href="http://stats.pingdom.com/','src="http://stats.pingdom.com/'),$txt); echo $txt; ?>
我测试过它的工作:)
更新
这是通过正则表达式完成并更好地工作:
<? $txt = file_get_contents('http://stats.pingdom.com/qmwwuwoz2b71/522741'); $domain = "http://stats.pingdom.com"; $txt = preg_replace("/(href|src)\=\"([^(http)])(\/)?/","$1=\"$domain$2",$txt); echo $txt; ?>
完成:D
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。