Convert relative path to absolute path

WBOY
Release: 2016-07-25 09:10:10
Original
1122 people have browsed it
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


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!