PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > PHP教程 > 正文

    php中把相对路径转化成绝对路径函数分享

    作者:w634381967来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:php中把相对路径转化成绝对路径函数分享,仅供学习。复制代码 代码如下:<?function relative_to_absolute($content, $feed_url) { pre...
    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; 


    ?>

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-10-836-1.html
    相关热词搜索: php 相对路径 绝对路径