php函数相对路径转化成绝对路径当使用php开发采集页面的时候,有时需要将网页中的相对路径自动转化成绝对路径,万维景盛为您分享在 Gregarius中提取的一个php函数。 <? function relative_to_absolute($content, $feed_url) { preg_match('/(http|https|ftp):\/\//', $feed_url, $protocol); $server_url = preg_replace("/(http|https|ftp|news):\/\//", "", $feed_url); $server_url = preg_replace("/\/.*/", "", $server_url); if ($server_url == '') { return $content; } if (isset($protocol[0])) { $new_content = preg_replace('/href="\//', 'href="'.$protocol[0].$server_url.'/', $content); $new_content = preg_replace('/src="\//', 'src="'.$protocol[0].$server_url.'/', $new_content); } else { $new_content = $content; } return $new_content; } ?>
|
>> 相关文章 |
关于我们
|
联系我们
|
付款方式
|
人才招聘
|
站长资讯
|
提交工单
Copyright© 2006-
值班客服QQ:
442956988
46472723
2920105656
热线电话:18610695105 售后技术支持:2920105656
1357089508
北京市大兴区西红门宏业路9号嘉悦广场2号楼1809