相对路径转化成绝对路径

yipeiwu_com6年前PHP代码库
提取 Gregarius中的一个函数。可以把网页中的相对路径自动转化成绝对路径。
<? 
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; 

?> 

相关文章

用PHP伪造referer突破网盘禁止外连的代码

比如我放纳米盘里的文件http://img.namipan.com/downfile/da333ee178bdad6531d1ec1540cf86277c116b6300887600/0...

php通过递归方式复制目录和子目录的方法

本文实例讲述了php通过递归方式复制目录和子目录的方法。分享给大家供大家参考。具体实现方法如下: <?php function recurse_copy($src,$...

php生成QRcode实例

php生成QRcode实例

本文实例讲述了php生成QRcode实例。是一个非常有用的功能。分享给大家供大家参考。具体如下: 实例演示效果如下图所示: 主要功能代码如下: <?php ini_...

详谈symfony window下的安装 安装时候出现的问题以及解决方法

1. cmd进入DOS  , cd 到 php.exe 的目录下 2. php -r "readfile('http://symfony.com/installer');" &...

深入探讨&quot;&amp;lt;br /&amp;gt;&quot;和 &quot;\r\n&quot; 两者有什么区别??

\r\n是输出的HTML代码换行,客户看到的效果没有换行。<br />则相反效果:我是内容\r\n我是内容我是内容<br />我是内容==============...