The problem of php regular matching

when collecting, there is a lot of a links in the crawled content!
in which I want to get

<ul class="list_box">
<li><a href="xxxx.html">xxxxx</a></li>
<li><a href="xxxx.html">xxxxx</a></li>
<li><a href="xxxx.html">xxxxx</a></li>
<li><a href="xxxx.html">xxxxx</a></li>
<li><a href="xxxx.html">xxxxx</a></li>
<li><a href="xxxx.html">xxxxx</a></li>
</ul>

but I can"t get every address. Is there a problem with my writing?

$patten = "/<ul\s*class=\"list_box\">\s*<li><a\s*href=\"(.*)\">(.*)<\/a><\/li>\s*<\/ul>/s";

what happens when you can"t match?
sometimes you can get but only one.
what I want is to traverse and collect all the an addresses.


is that what you want?

clipboard.png

<ul class="list_box">\s(<li><a\s*href=\"(.*)\">(.*)</a><\/li>\s)*</ul>

=

to get all the url senses, you have to take two steps

Code

<?php
$strPattern = '/<ul class="list_box">\s(?<lists>.*?)<\/ul>/s';
$strSubject = '<ul class="list_box">
<li><a href="xxxx1.html">xxxxx</a></li>
<li><a href="xxxx2.html">xxxxx</a></li>
<li><a href="xxxx3.html">xxxxx</a></li>
<li><a href="xxxx4.html">xxxxx</a></li>
<li><a href="xxxx5.html">xxxxx</a></li>
<li><a href="xxxx6.html">xxxxx</a></li>
</ul>';
preg_match_all($strPattern, $strSubject, $arrMatches);

$strPattern2 = '/<li><a\s*href=\"(?<url>.*?)\">(.*?)<\/a><\/li>\s/s';
preg_match_all($strPattern2, $arrMatches['lists'][0], $arrMatches2);
var_dump($arrMatches2['url']);

result

array(6) {
  [0]=>
  string(10) "xxxx1.html"
  [1]=>
  string(10) "xxxx2.html"
  [2]=>
  string(10) "xxxx3.html"
  [3]=>
  string(10) "xxxx4.html"
  [4]=>
  string(10) "xxxx5.html"
  [5]=>
  string(10) "xxxx6.html"
}

$html = <<< HTML
<ul class="list_box">
    <li><a href="xxxx.html">xxxxx</a></li>
    <li><a href="xxxx.html">xxxxx</a></li>
    <li><a href="xxxx.html">xxxxx</a></li>
    <li><a href="xxxx.html">xxxxx</a></li>
    <li><a href="xxxx.html">xxxxx</a></li>
    <li><a href="xxxx.html">xxxxx</a></li>
</ul>
HTML;

$pattern_href = '/href=[\"\'](.*)[\"\']/i';
preg_match_all($pattern_href, $html, $href);
var_dump($href[1]);

$pattern_title = "/[\"\"]\>(.*)\<\/a\>/i';
preg_match_all($pattern_title, $html, $title);
var_dump($title[1]);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35116-2bf7b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35116-2bf7b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?