i need to receive number of pages in html page ,i started to write this code how to fix this code in php ? my html code is : <li class='current'><B>1</B> / 385</li><a href='website' ,i need to receive number 385 in php <?php $website="websitex"; $content=file_get_contents($website); $stripped_file = strip_tags($content, "<a><li>"); //echo $stripped_file ."<br>"; $start=strpos($stripped_file,'<li class'); echo $start ."<br>": ?> Code (markup):
Hi simon, Here is a snippet based on your example that should get you going : $content="<li class='current'><B>1</B> / 381</li><a href='website' ,i need to receive number 385 in php"; $startsAt = strpos($content, "<B>1</B> /") + strlen("<B>1</B> /"); $endsAt = strpos($content, "</li><a href='website'", $startsAt); $result = substr($content, $startsAt, $endsAt - $startsAt); echo $result; PHP: No regular expression there. Hope it helps
Another way of doing it: $a = "<li class='current'><B>1</B> / 385</li><a href='website'"; preg_match_all('/\d+/', $a, $res); echo "Showing: {$res[0][0]} To {$res[0][1]}"; PHP: Assuming they are the first two numbers in the string.