Reputation: 1292
Eg:
$str .= "Additional tax(2.34)";
$str .= "Additional tax(3)";
Can anyone help me up to extract the number from the string. I need an array format like this
Array ( [0] => 2.34 [1] => 3 );
Upvotes: 0
Views: 4801
Reputation: 120644
This should do it:
<?php
$str = '';
$str .= "Additional tax(2.34)";
$str .= "Additional tax(3)";
if (preg_match_all('/\((\d+(?:\.\d+)?)\)/', $str, $matches) > 0) {
var_dump($matches[1]);
}
?>
Upvotes: 7