gpt4 book ai didi

php - 在 PHP 中按美元值切割字符串

转载 作者:可可西里 更新时间:2023-11-01 00:56:18 26 4
gpt4 key购买 nike

我有这样一个字符串:

Medical services provided by members of regulated professions, 
Dr. Rachel G. Barry with no value $ 2.000,00 , Dr. James Silva
with value of $ 5.000,00 and Dr. Joey House with no value $ 6.500,00

(插入换行符只是为了便于阅读)

我如何识别美元、$2.000,00、$5.000,00 和 $6.500,00 中的值,以及像这样可爱的字符串:

Part 1:  Medical services provided by members of regulated professions, Dr. Rachel G. Barry with value of  $ 2.000,00

Part 2: Dr. James Silva with value of $ 5.000,00

Part 3: Dr. Joey House with value of $ 6.500,00

我可以使用正则表达式以美元为单位查找值,但我如何截断前一句?

最佳答案

你好,我有一个解决方案,但只适用于这个字符串,但你可以这样做。

<?php 
$str = "Medical services provided by members of regulated professions, Dr. Rachel G. Barry with no value $ 2,000.00, Dr. James Silva with value of $ 5,000.00 and Dr. Joey House with no value $ 6,500.00";
$arr = @explode(".00", $str);
echo $arr[0];
echo "<br/>";
echo str_replace(", ","", $arr[1]);
echo "<br/>";
echo str_replace("and","", $arr[2]);
?>

关于php - 在 PHP 中按美元值切割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41976851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com