Home >Backend Development >PHP Tutorial >Convert relative path to absolute path

Convert relative path to absolute path

WBOY
WBOYOriginal
2016-07-25 09:10:101169browse
Convert relative path to absolute path
  1. //Convert relative path to absolute path
  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. //Open source OSPhP.COM.CN
  6. $server_url = preg_replace("// .*/", "", $server_url);
  7. if ($server_url == '') {
  8. return $content;
  9. }
  10. if (isset($protocol[0])) {
  11. //Open source code OSPhP. COm.CN
  12. $new_content = preg_replace('/href="//', 'href="'.$protocol[0].$server_url.'/', $content);
  13. $new_content = preg_replace('/src ="//', 'src="'.$protocol[0].$server_url.'/', $new_content); //Open source OSPhP.COM.CN
  14. } else {
  15. $new_content = $content;
  16. }
  17. return $new_content;
  18. }
  19. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Parsing of java folderNext article:Parsing of java folder