Reputation: 10828
I am trying to get the ID from transaction(123456)
in the HTML
It doesn't seem to return anything.
$response = "</body> </html><script type='text/javascript'>transaction(123456);</script>";
preg_match('/^transaction\((\d+)\)/', $response, $match);
print_r($match);
if (is_numeric($match[1])) {
echo "Your ID: " . $match[1];
}
Upvotes: 1
Views: 1748
Reputation: 2790
$response = "</body> </html><script type='text/javascript'>transaction(123456);</script>";
preg_match('/transaction\((\d+)\)/', $response, $match);
print_r($match);
if (is_numeric($match[1])) {
echo "Your ID: " . $match[1];
}
This is the code you want. The reason is, that your pattern started with "^" and this character means, that you expect taht "transaction" appears in the front of your string "$response", but there is "..."
Upvotes: 1
Reputation: 60007
preg_match('/^transaction\((\d+)\)/', $response, $match);
should be
preg_match('/transaction\((\d+)\)/', $response, $match);
Upvotes: 1