加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php 获得当前的脚本网址和相对路径转化成绝对路径正则

发布时间:2020-12-13 20:28:46 所属栏目: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 ); $se

获得当前的脚本网址和相对路径转化成绝对路径正则

  1. <?  
  2.  
  3. function relative_to_absolute($content$feed_url) {   
  4. preg_match('/(http|https|ftp):///'$feed_url$protocol);   
  5. $server_url = preg_replace("/(http|https|ftp|news):///"""$feed_url);  
  6. $server_url = preg_replace("//.*/"$server_url);   
  7.     if ($server_url == '') {   
  8.         return $content;   
  9.     }   
  10.     if (isset($protocol[0])) {   
  11. $new_content = preg_replace('/href="//''href="'.$protocol[0].$server_url.'/'$content);   
  12. $new_content = preg_replace('/src="//''src="'.$protocol[0].$server_url.'/'$new_content);   
  13.     } else {   
  14. $new_content = $content;   
  15.     }   
  16.     return $new_content;   
  17. }   
  18. ?> 

获得当前的脚本网址

  1. <?  
  2. function get_php_url(){  
  3.         if(!emptyempty($_server["request_uri"])){ 
  4.  
  5. $scriptname = $_server["request_uri"];  
  6. $nowurl = $scriptname;  
  7.         }else{  
  8. $scriptname = $_server["php_self"]; //  
  9.                 if(emptyempty($_server["query_string"])) $nowurl = $scriptname;  
  10.                 else $nowurl = $scriptname."?".$_server["query_string"];  
  11.         } 
  12. // 
  13.         return $nowurl;  

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读