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

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

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

获得当前的脚本网址

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