Reputation: 2866
<span class="nowrap">
<span class="use_sprites stars4 stars4i5" title="5 start hotel">
</span>
I need to fetch the single number 5 that is in between title.
Here is my attempt:
preg_match_all('#<span class="nowrap">\s*(.*?)\s*<\/span>#s', $htmlOfPage, $rate);
The above code fetches the following:
<span class="use_sprites stars4 stars4i5" title="5 start hotel">
Question:
<span class="nowrap">
</span>
title="5 start hotel"
the single number in between title
I need to start from Starting point and ignore everything except title="..." and in title grab the single number. By now, we already at the end point.
Any help how to do the above steps?
Upvotes: 1
Views: 109
Reputation: 4097
$str = '<span class="nowrap">
<span class="use_sprites stars4 stars4i5" title="5 start hotel">
</span>';
preg_match('/<span class="nowrap">.+? title="([0-9]){1}/sm', $str, $match);
print_r($match);
Output:
Array
(
[0] => <span class="nowrap">
<span class="use_sprites stars4 stars4i5" title="5
[1] => 5
)
Make sure you look at the source code for the match. It will not show up in the browser window because of the span tags
That should just match the number you are looking for
Upvotes: 2