【发布时间】:2018-10-15 18:53:33
【问题描述】:
我想将../ 转换为完整路径。例如我在https://example.com/folder1/folder2/style.css 中的css 中有以下网址
img/example1.png
/img/example2.png
../img/example3.png
../../img/example4.png
https://example.com/folder1/folder2/example5.png
我想将它们转换为完整路径,如下所示
https://example.com/folder1/folder2/img/example1.png
https://example.com/folder1/folder2/img/example1.png
https://example.com/folder1/img/example1.png
https://example.com/img/example1.png
https://example.com/folder1/folder2/example5.png
我尝试了类似下面的方法
$domain = "https://example.com";
function convertPath($str)
{
global $domain;
if(substr( $str, 0, 4 ) == "http")
{
return $str;
}
if(substr( $str, 0, 1 ) == "/")
{
return $domain.$str;
}
}
我知道这很复杂,这种操作一定有一些简单的方法。请指导我。谢谢。
【问题讨论】:
-
我正在使用 php 创建类似 httrack 的东西,所以基本 url 无济于事
-
不确定这是否有帮助,否则,请尝试以下查询“php convert relative to absolute url”:stackoverflow.com/questions/4444475/…