preg_match - get numeric value from a function
I am trying to get the value from transaction
function.
Example:
$response = "transaction(12346675); $('#Tracking').html('<script> random random random</script>');";
I want to get 12346675
value. How can that be done?
I have tried preg_match('/([\w\_\d]+)\(([\w\W]*)\)/', $response, $match);
but it dont seem to work开发者_Go百科.
Thanks
preg_match('/^transaction\((\d+)\)/', $str, $m);
print_r($m);
Generalized patterns:
^\s*\w+\s*\(\s*(\d+)\s*\)
- If function name is a PHP identifier:
^\s*[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\s*\(\s*(\d+)\s*\)
For similar question, see: Regex Help, Search for function names and return them
reg_match('/\D+\((\d+)\)\.*/', $response, $match);
Fetching the number after the first word, provided it is enclosed in parentheses:
preg_match('/\w+\((\d+)\)/', $response, $match);
If you're looking for the first number of the line, then there's no need to complicate it with the second half of your expression:
preg_match('/(\d+)/', $response, $match);
This is a simple match for the first number found on your line.
精彩评论