Home  >  Article  >  Backend Development  >  超链接转换成绝对地址,能否完全使用正则解决?该如何处理

超链接转换成绝对地址,能否完全使用正则解决?该如何处理

WBOY
WBOYOriginal
2016-06-13 10:11:301055browse

超链接转换成绝对地址,能否完全使用正则解决?
从网页抓取到的超链接格式多变,怎样全部转换成绝对地址呢?

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $paths=array("http://we.us","x.y.z","a.b.cn/en/","http://a.b.cn/en/js","a.b.cn/js/","a.b.cn/en/js/ext","a.b.cn/en/css/ext/");$files=array("http://so.do.i","http://a.b.cn/","./","../","../../","../js/","/js","/css/blue.css","../../en/js/ad.js");foreach($paths as $path){  foreach($files as $file){    echo realfile($path,$file);  }}function realfile($path,$file){//返回文件file的绝对地址,//如果文件地址是相对地址,则以路径path为参照/*    $real=$path.$file;//要完善的内容*/    return '<li>'.$real.'';}?>


------解决方案--------------------
舉例說明,沒看太懂你要的效果.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:如何嵌套Next article:ThinkPHP令牌异常如何解决