当前位置:Gxlcms > PHP教程 > 相对路径转化成绝对路径

相对路径转化成绝对路径

时间:2021-07-01 10:21:17 帮助过:18人阅读

相对路径转化成绝对路径
  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. //开源OSPhP.COM.CN
  6. $server_url = preg_replace("//.*/", "", $server_url);
  7. if ($server_url == '') {
  8. return $content;
  9. }
  10. if (isset($protocol[0])) {
  11. //开源代码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); //开源OSPhP.COM.CN
  14. } else {
  15. $new_content = $content;
  16. }
  17. return $new_content;
  18. }
  19. ?>

人气教程排行