I am trying to isolate a percentage value in a line of text. This should be pretty easy with preg_match, but since the percent sign is used as the operator in preg_match, I cannot find any sample code by doing a search.
$string = 'I want to get the 10% out of this string';
In the end, I want:
$percentage = '10%';
I assume that I need something like:
$percentage_match = preg_match("/[0-99]%/", $string);
I am sure there is a very quick answer to this, but the solution is evading me!
source
share