繁体   English   中英

PHP正则表达式百分比或货币

[英]PHP Regular expression percent or currency

我将需要能够在PHP中提取以下内容,这使我发疯。

以以下字符串为例:

$text = "Nalgene Narrow-Mouth Loop-Top 16-oz. Water Bottle for $4 + pickup and %40 off at REI";

一方面,我需要能够提取:

$4 as extracted currency

%40 as extracted percentage

并区分哪个是货币,哪个是百分比。

为了使它更复杂一点,如果货币是,我也应该抓住它:

$4.11 or $ 4.10 (not the spacing and the comma)

或该百分比是否为:

% 40 (note the spacing)

我真的被卡住了,谢谢..

$text = "Nalgene Narrow-Mouth Loop-Top 16-oz. Water Bottle for $4.3 + pickup and % 40 off at REI";
preg_match('/%([ 0-9]+?) /', $text, $matches);
print_r($matches);
preg_match('/\$([ .0-9]+?) /', $text, $matches);
print_r($matches);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM