I have an html that contains this markup.
<font class="count">Total count is: 20</font>
How do I use preg_match to get the total count line, which is 20
in this case.
I have an html that contains this markup.
<font class="count">Total count is: 20</font>
How do I use preg_match to get the total count line, which is 20
in this case.
This is simple:
$string = '<font class="count">Total count is: 20</font>';
preg_match('/Total count is:\s+(\d+)/', $string, $match);
echo $match[1]; // 20
Otherwise use a DOM method if you want to find the <font>
tag within other HTML to extract the text portion of the font node and then grab the number at end of the node value.
Here is another way just for fun:
$string = '<font class="count">Total count is: 20</font>';
$string = filter_var($string, FILTER_SANITIZE_NUMBER_INT);
echo $string; // 20
And another:
$string = '<font class="count">Total count is: 20</font>';
$string = ltrim(strrchr(strip_tags($string), ' '));
echo $string; // 20