I have a html list that looks like this:
- animals (45)
- houses (36)
- computers (96)
I want to get all the values inside those ()
and make like $sum = 45+36+96;
How can I do that? Thanks
I have a html list that looks like this:
I want to get all the values inside those ()
and make like $sum = 45+36+96;
How can I do that? Thanks
assuming that the html content is already in a php variable like $list,
preg_match_all('{<li>[a-zA-Z\s]*\s\(([0-9]*)\)</li>}', $list, $matches);
$sum = array_sum($matches[1]);
for <li><span><a href="">
, you can modify the regex to something like
preg_match_all('{<li>(["=a-zA-Z<>\s]*)\s\(([0-9]*)\)([/a-zA-Z<>\s]*)</li>}',
$list, $matches);
$sum = array_sum($matches[2]);