【发布时间】:2015-10-12 21:22:25
【问题描述】:
我试图获取两个括号 () 之间的值的每个实例。我的函数返回数组中的每个字符,而不是它应该返回的两个字符串。我猜模式中有什么东西?我一直在尝试不同的方法。任何帮助将不胜感激。
$formula = "if([Paid] === 1, 'Need To Pay', 'Paid Up')+if([Paid] === 1, 'Million', 'Good to Go')"
我的班级:
<?php
class Formula {
public function explode_formula($formula){
echo $this->get_string_between($formula, "(", ")");
}
public function get_string_between($string, $start, $end){
preg_match_all("~((.+?))~", $string, $m);
print_r($m[1]);
}
}
需要返回:
[Paid] === 1, 'Need To Pay', 'Paid Up'
[Paid] === 1, 'Million', 'Good to Go'
【问题讨论】:
-
您必须转义文字
\(括号才能让正则表达式找到它们。
标签: php arrays preg-match-all