首页 > 语言 > PHP > 正文

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

2024-09-04 11:47:14
字体:大 中 小
来源:转载
供稿:网友

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

  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;  
  14. } 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表