0

我使用 curl 和绝对链接从外部站点显示运动器材,效果很好。问题是外部站点没有正确排序结果。我可以这样做,也许是指外部页面的标签。

这是我的代码:

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.sportingpulse.com/mobile/mobile.cgi?a=CL&aID=2307");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
$result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://www.sportingpulse.com/mobile/$2$3', $result);
echo $result
?>

这是我希望按年龄组排序的结果(可能使用 class="list-name")或任何其他建议:

        <ul class="options" data-role="listview">
<li role="heading" data-role="list-divider">Please choose your Competition</li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223601"><div class="list-name">2012 Winter 23 Girls A</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223608"><div class="list-name">2012 Winter 18 Boys A</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223691"><div class="list-name">2012 Winter 23 Girls AR</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223637"><div class="list-name">2012 Winter 18 Boys AR</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223578"><div class="list-name">2012 Winter 18 Boys B</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223711"><div class="list-name">2012 Winter 23 Girls B</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223620"><div class="list-name">2012 Winter 18 Boys BR</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223661"><div class="list-name">2012 Winter 18 Girls BR</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223573"><div class="list-name">2012 Winter 18 Boys C</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223639"><div class="list-name">2012 Winter 23 Girls BR</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223679"><div class="list-name">2012 Winter 23 Girls C</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223676"><div class="list-name">2012 Winter 20 Boys A</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223579"><div class="list-name">2012 Winter 20 Boys AR</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223686"><div class="list-name">2012 Winter 23 Boys A</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223592"><div class="list-name">2012 Winter 20 Boys B</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223704"><div class="list-name">2012 Winter 23 Boys AR</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223662"><div class="list-name">2012 Winter 23 Boys B</div></a></li>
      <li><a href="http://www.sportingpulse.com/mobile/mobile.cgi?a=CF&amp;aID=2307&amp;cID=223685"><div class="list-name">2012 Winter 23 Boys BR</div></a></li>
</ul>
4

1 回答 1

0

这可以按字母顺序对包含在 class="option" 中的链接进行排序,从而对年龄组进行排序

sort('ul.options>li', 'a');
function sort(list, key) {
    $($(list).get().reverse()).each(function(outer) {
        var sorting = this;
        $($(list).get().reverse()).each(function(inner) {
            if($(key, this).text().localeCompare($(key, sorting).text()) > 0) {
                this.parentNode.insertBefore(sorting.parentNode.removeChild(sorting), this);
            }
        });
    });
}
于 2012-08-03T08:06:58.507 回答