I am having an issue getting a detailed preg_match_all to work. I keep getting a blank Array.
Here is my code:
<?php
$remote_search = file_get_contents('http://wiki.seg.org/index.php?title=Special%3ASearch&search=drilling&button=');
preg_match_all('%<li><div class=\'mw-search-result-heading\'><a href="(.*)" title="(.*)">(.*)</a> </div> <div class=\'searchresult\'>(.*)</div>
<div class=\'mw-search-result-data\'>(.*)</div></li>%si', $remote_search, $links);
echo '<ul class=\'mw-search-results\'>';
for($i = 0; $i < count($links[1]); $i++) {
echo '<li><div class=\'mw-search-result-heading\'><a href="' . $links[5][$i] . '" title="' . $links[4][$i] . '">' . $links[3][$i] . '<\/a> </div> <div class=\'searchresult\'>' . $links[2][$i] . '<\/div><div class=\'mw-search-result-data\'>' . $links[1][$i] . '<\/div><\/li>';
}
echo '</ul>';
?>
I am trying to grab the link details from code shown below:
<li><div class='mw-search-result-heading'><a href="/index.php/Dictionary:Cable_drilling" title="Dictionary:Cable drilling">Dictionary:Cable drilling</a> </div> <div class='searchresult'>{{lowercase}}{{#category_index:C|cable <span class='searchmatch'>drilling</span>}}
</div>
<div class='mw-search-result-data'>132 B (22 words) - 19:58, 20 December 2011</div></li>
When I perform a var_dump($links);
I get Array
as the result.
The code below works to grab the contents in the section I am trying to pull the variables.
<?php
$remote_search = file_get_contents('http://wiki.seg.org/index.php?title=Special%3ASearch&search=drilling&button=');
preg_match_all('%<ul class=\'mw-search-results\'>(.*)</ul>%si', $remote_search, $links);
$bar = $links[0];
echo '<ul class=\'mw-search-results\'>';
echo $bar;
echo '</ul>';
var_dump($links);
?>
The echo $bar;
results in Array
and no ouput.
The var_dump($links);
in this snippet outputs the content of the ul.
Does anyone see the error in my top snippet that is preventing me from parsing the code the way I am intending it?