我有这个total USD100.75 from
字符串。我正在接受下一个单词
$s = 'total USD100.75 from';
$r = preg_match_all('/(?<=(total))(\s\w*)/',$s,$matches);
print_r($matches[0]);
但是我希望在两个特定字符串之间得到字符串,即total
和from
。我怎么能得到中间的字符串?。
答案 0 :(得分:1)
您也可以使用正则表达式,例如
'/total (.*?) from/'
答案 1 :(得分:1)
使用substr
和strlen
:
echo substr($string, strlen("total "), -strlen(" from"));
答案 2 :(得分:1)
我不确定你的语言的具体细节,但在Java中:
(?USD[0-9]+\.[0-9]{2})
会起作用。
如果您有逗号,可以尝试:
(?USD[0-9]{1,3}(,?[0-9]{3})*\.[0-9]{2})
答案 3 :(得分:0)
您可以按空格分解字符串。
$s = 'total USD100.75 from';
$s1 = explode(" ", $s);
echo $s1[1];
<强>输出强>
USD100.75
<强> Demo 强>
答案 4 :(得分:0)
正则表达式很容易实现。你只需要了解基础知识。 您将通过以下模式实现您想要的目标:
total\s(.*)\sfrom
答案 5 :(得分:0)
@ user3272483,请在下面的答案中查看您的解决方案。
$matches = array();
preg_match("/total (.*?) from/", 'total USD100.75 from', $matches);
print_r($matches);