【问题标题】:PHP extract specific from url <a id=id class=class href=www.link.com?_pgn=PHP 从 url 提取特定的 <a id=id class=class href=www.link.com?_pgn=
【发布时间】:2012-07-30 16:57:03
【问题描述】:

html链接是:

 <a title="Next page of results" class="sprBtnSRP1 enabled" href="http://www.link.com/page.html?thisisthelink&_pgn=2&_al=25&at=tc"><i>Next</i><b class="sprBtnSRP1"></b></a>

php 是:

function NextLink($url){
        $html= WGET($url);
        $urlpattern1 = '/Next"><a[^>]+pgn=([^"]+)/i';
        preg_match_all($urlpattern1, $html, $matches1);
        $nextlink='http://www.link.com/page.html?thisisthelink&_pgn=';
         foreach ($matches1[1] as $u) {
            $nextlink = $nextlink.$u;
         }
        return $nextlink;
    }

================

不再工作了,我需要在 PHP 中将 $nexlink.$u 变成 http://www.link.com/page.html?thisisthelink&amp;_pgn=2&amp;_al=25&amp;at=tc

问题是 $urlpattern1

提前感谢您的帮助!

【问题讨论】:

    标签: php hyperlink href extract


    【解决方案1】:

    试试这个模式:

    $urlpattern1 = '/<a\s+.*?href=".*?_pgn=(.*?)".*?>/i';
    

    编辑:

    如果你只想要那个链接,那么你可以使用标题(或其他参数)作为提示,试试这个模式:

    $urlpattern1 = '/<a\s+.*?title="Next page of results"\s+.*?href=".*?\_pgn=(.*?)".*?>/i';
    

    【讨论】:

    • 问题是 _pgn= 必须从特定的 url 中提取:&lt;a title="Next page of results" class="sprBtnSRP1 enabled" href="http://www.link.com/page.html?thisisthelink&amp;_pgn=2&amp;_al=25&amp;at=tc"&gt;&lt;i&gt;Next&lt;/i&gt;&lt;b class="sprBtnSRP1"&gt;&lt;/b&gt;&lt;/a&gt; 因为在 html 页面上我有很多链接,并且必须使用这个指定的链接第 i 个模式。 .. 请原谅我的英语
    猜你喜欢
    • 2022-08-10
    • 1970-01-01
    • 2011-03-18
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    • 2019-10-11
    • 1970-01-01
    相关资源
    最近更新 更多