Pau*_*aul 6 php regex preg-match
我试图在一串文本中隔离百分比值.使用preg_match这应该很简单,但因为百分号在preg_match中用作运算符,所以我无法通过搜索找到任何示例代码.
$string = 'I want to get the 10% out of this string';
Run Code Online (Sandbox Code Playgroud)
我最终想要的是:
$percentage = '10%';
Run Code Online (Sandbox Code Playgroud)
我的猜测是我需要这样的东西:
$percentage_match = preg_match("/[0-99]%/", $string);
Run Code Online (Sandbox Code Playgroud)
我确信有一个非常快速的答案,但解决方案是逃避我!
if (preg_match("/[0-9]+%/", $string, $matches)) {
$percentage = $matches[0];
echo $percentage;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6897 次 |
最近记录: |