Currently I'm scraping data from a page of HTML. One of my code is not working. The HTML content has something like this.
<ul class="pagination">
<li>
<span class="page active">
1
</span>
</li>
<li>
<a class="page available" href="/somethingherewithanychars1">
2
</a>
</li>
<li>
<a class="page available" href="/somethingherewithanychars2">
3
</a>
</li>
<li>
<a class="page available" href="/somethingherewithanychars3">
4
</a>
</li>
<ul>
i tried this code to get the href value next to the active page link, like in the example the active page link is page number 1 so the href value that i will get must be page number 2 where the value is /somethingherewithanychars1 but it is not working
$file_string = file_get_contents($url);
preg_match('/<li><span class="page active">.*?<\/span><\/li><li><a class="page available" href="(.*)">/i', $file_string, $pages);
print_r($pages);
The html that i was accessing has some code like this
<div class="attributes">
<a class="name" href="/linksTothissite" data-hovercard-id="somechars">link1</a>
<span class="list">
USA
</span>
<a class="name" href="/linksTothissite" data-hovercard-id="somechars">link2</a>
<span class="list">
CANADA
</span>
</div>
I tried getting the values using this code, and i can get the link1 and link2
preg_match_all('/<a class="name" href=".*?" data-hovercard-id=".*?">(.*)<\/a>/i', $file_string, $values);
also this one i can get the USA, and CANADA
preg_match_all('/<span class="list">(.*?)<\/span>/s',$file_string, $values);
$val= $values[1];
Why is my preg_match not getting the value i need? i tried using also pre_match_all() but still i get an output in my print_r Array ( ), but the rest of my code works.