I am currently trying to extract a numeric value from an html string. I am currently using preg_match
but to no luck. All I desire is to get the numeric value set as param of a javascript function myFunction
. As of now I get an empty array. Any help to achieve this?
$data = "<th style='text-align:center;width:33%;'><a onclick='return myfunction(12314568);' href='#test' class='btn mini full'>Test</a> </th>";
preg_match("/\[return myfunction([0-9]+)\]/", $data, $m);
print_r($m);
The brackets need to be removed and the parentheses need to be escaped since they actually appear in the string. You'll then need another set of parentheses to group the numbers so they are separated:
preg_match("/return myfunction\(([0-9]+)\)/", $data, $m);