相对路径转化成绝对路径

yipeiwu_com5年前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获取从html表单传递数组的方法

本文实例讲述了php获取从html表单传递数组的方法。分享给大家供大家参考。具体如下: 将表单的各个元素的name都设置成同一个数组对象既可以以数组的方式传递表单值 html页面如下:...

php expects parameter 1 to be resource, array given 错误

如果你使用的是封装好的类 例如 function fetch_array($query, $result_type = MYSQL_ASSOC) { return mysql_fetch...

php类的定义与继承用法实例

本文实例讲述了php类的定义与继承用法。分享给大家供大家参考。具体如下: <?php /* * class */ class people { public...

PHP 计算两个时间段之间交集的天数函数方法

函数:/**  * 计算两个时间段之间交集的天数  * @param $startDate1 开始日期1  * @...

一个PHP验证码类代码分享(已封装成类)

复制代码 代码如下: <?php session_start(); Header("Content-type: image/gif"); class SecurityCode {...