php 相对路径转成绝对路径的简单示例

前端之家收集整理的这篇文章主要介绍了php 相对路径转成绝对路径的简单示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
PHP相对路径转换成绝对路径感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!
  1. <?
  2. /**
  3. * PHP相对路径转换成绝对路径
  4. *
  5. * @param
  6. * @author 编程之家 jb51.cc jb51.cc
  7. **/
  8. function relative_to_absolute($content,$Feed_url) {
  9. preg_match('/(http|https|ftp):///',$Feed_url,$protocol);
  10. $server_url = preg_replace("/(http|https|ftp|news):///","",$Feed_url);
  11. $server_url = preg_replace("//.*/",$server_url);
  12. if ($server_url == '') {
  13. return $content;
  14. }
  15. if (isset($protocol[0])) {
  16. $new_content = preg_replace('/href="//','href="'.$protocol[0].$server_url.'/',$content);
  17. $new_content = preg_replace('/src="//','src="'.$protocol[0].$server_url.'/',$new_content);
  18. } else {
  19. $new_content = $content;
  20. }
  21. return $new_content;
  22. }
  23. /*** 来自编程之家 jb51.cc(jb51.cc) ***/

猜你在找的PHP相关文章