【问题标题】:simple_html_dom and Net_URL2 to normalize relative pathssimple_html_dom 和 Net_URL2 规范化相对路径
【发布时间】:2012-04-24 11:34:06
【问题描述】:

我正在尝试使用 simple_html_domNet_URL2 规范化到完整 url 的相对路径,像 src="/my_path" 这样的路径被 this 这样的脚本规范化,但像这样的路径:src="my_path" 不是!如何标准化这样的路径?

例子:

$uri = new Net_URL2("http://test.com");
print $uri->resolve('/my_path') . "\n"; // works
print $uri->resolve('my_path') . "\n";  // doesn't work!

【问题讨论】:

    标签: php relative-path simple-html-dom


    【解决方案1】:

    您描述的是 Net_URL2 中的一个已知错误:http://pear.php.net/bugs/bug.php?id=19176

    ticket有补丁修复,但是pear包本身还没有修复。补丁:

    Index: Net/URL2.php
    ===================================================================
    --- Net/URL2.php    (revision 323857)
    +++ Net/URL2.php    (revision )
    @@ -720,7 +720,7 @@
                         } else {
                             // Merge paths (RFC 3986, section 5.2.3)
                             if ($this->_host !== false && $this->_path == '') {
    -                            $target->_path = '/' . $this->_path;
    +                            $target->_path = '/' . $reference->_path;
                             } else {
                                 $i = strrpos($this->_path, '/');
                                 if ($i !== false) {
    

    【讨论】:

      猜你喜欢
      • 2019-10-12
      • 1970-01-01
      • 2023-03-05
      • 2010-09-15
      • 1970-01-01
      • 2010-11-17
      • 2012-07-14
      • 2013-02-13
      • 2022-10-01
      相关资源
      最近更新 更多