I’m trying to isolate the percentage value in a string of text. This should be pretty easy using preg_match, but because the percentage sign is used as an operator in preg_match I can’t find any sample code by searching.
$string = 'I want to get the 10% out of this string';
What I want to end up with is:
$percentage = '10%';
My guess is that I’ll need something like:
$percentage_match = preg_match("/[0-99]%/", $string);
I’m sure there is a very quick answer to this, but the solution is evading me!
1 Answer