php - Find a percentage value in a string using preg_match -
i'm trying isolate percentage value in string of text. should pretty easy using preg_match, because percentage sign used operator in preg_match can't find sample code searching.
$string = 'i want 10%  out of string'; what want end is:
$percentage = '10%'; my guess i'll need like:
$percentage_match = preg_match("/[0-99]%/", $string); i'm sure there quick answer this, solution evading me!
if (preg_match("/[0-9]+%/", $string, $matches)) {     $percentage = $matches[0];     echo $percentage; } 
Comments
Post a Comment