相对路径转化成绝对路径

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实现通过正则表达式替换回调的内容标签

本文实例讲述了PHP实现通过正则表达式替换回调的内容标签。分享给大家供大家参考。具体实现方法如下: function my_wp_plugin_tag_action($content...

php array_unique之后json_encode需要注意

例如:array_unique(array(1, 1, 2)); 他的结果是 array(2) { [0]=> int(1) [2]=> int(2) } 这就不是numer...

PHP屏蔽蜘蛛访问代码及常用搜索引擎的HTTP_USER_AGENT

PHP屏蔽蜘蛛访问代码及常用搜索引擎的HTTP_USER_AGENT

PHP屏蔽蜘蛛访问代码代码: 常用搜索引擎名与 HTTP_USER_AGENT对应值 百度baiduspider 谷歌googlebot 搜狗sogou 腾讯SOSOsosospide...

PHP更新购物车数量(表单部分/PHP处理部分)

表单部分: 复制代码 代码如下: <form action="?action=edit_num" method="post" name="car<?php $c_rs['id...

解析php中获取url与物理路径的总结

在这里我想总结一下取得地址栏内URL及文件所属的我更路径的一些信息:运用$_SERVER[ ]我们可以来完成许多事情:它是一个包含头部(headers),路径信息及脚本位置的数组,数组的...