Php 如何仅获取美元符号后的数字
如果$str类似于Php 如何仅获取美元符号后的数字,php,regex,Php,Regex,如果$str类似于sokewe(字母)$10,00 sequee(字母)如何仅获取美元符号后的数字 例如:索基维(信)$10,00索基维(信)索基维(信)$1000索基维(信) 捕获它: if (preg_match('/\$\s([0-9])/',$str, $matches)) { ^-----^ ^^^^^^^^^^ $digit = $matches[1]; } 您可以使用: if (preg_match('/\$\D*(\d
sokewe(字母)$10,00 sequee(字母)
如何仅获取美元符号后的数字
例如:索基维(信)$10,00索基维(信)索基维(信)$1000索基维(信)
捕获它:
if (preg_match('/\$\s([0-9])/',$str, $matches)) {
^-----^ ^^^^^^^^^^
$digit = $matches[1];
}
您可以使用:
if (preg_match('/\$\D*(\d+(?:,\d+)*)/', $input, $matches)) {
echo $matches[1] . "\n"; // 10,00
}
您好,您只需要使用php正则表达式
$str = '$10.00';
preg_match('/\d+(,|.)?\d+/',$str,$matches);
print_r($matches);
您可能还需要进行测试。万一我有command(,)和dot(.),因为你有$,€,符号和金额可以用点或逗号表示
如果您想测试它,可以使用以下链接尝试以下操作:
if(preg_match('/([£$€])([0-9]+[.,]?(?:[0-9]{2})?)/', $str, $matches)) {
$currency = $matches[1];
$value = $matches[2];
}
例如。
您可以使用substr和strrchr
$string='$10,00'
$return=substr(strrchr($string,“$”),1)
回音$return//10,00
你想在输出中< <代码> 10 > /代码>代码> 10,00 < /代码>他说数字,所以也许只有1i想要1000,如果有使用,在Digigas A注释中,考虑<代码> <代码>量词在<代码> s?<代码>中,你甚至可以捕获另一组中的货币!代码>/([$)\s?([0-9])/
我试图添加这样的组“/([$)\D*(\D+(?:,\D+)/”我做错了什么吗???,请确保现在使用匹配的组2,即$匹配[2]
if(preg_match('/([£$€])([0-9]+[.,]?(?:[0-9]{2})?)/', $str, $matches)) {
$currency = $matches[1];
$value = $matches[2];
}