我很弱,正则表达式,需要帮助。我的问题是我必须提取所有匹配给定模式的字符串,我已经成为一个数组。请参见下面的问题:PHP字符串提取
字符串
<?php
$alert_types = array(
'warning' => array('', __l("Warning!")),
'error' => array('alert-error', __l("Error!")),
'success' => array('alert-success', __l("Success!")),
'info' => array('alert-info', __l("For your information.")),
);?>
该守则的preg_match
preg_match("/.*[_][_][l][\(]['\"](.*)['\"][\)].*/", $content, $matches);
我只获得了第一个比赛是警告!。我期待的比赛将具有以下值:
Warning!, Error!, Success!, For your information.
其实我使用的file_get_contents($文件)来获得字符串。
任何人都可以帮助我解决这个问题。先谢谢你。
抱歉,我应该使用preg_match_all而不是preg_match – lukaserat
@mario是的,你说得对。我也解决了这个问题,但没有考虑可能的重复。 :)这是我的正则表达式:preg_match_all(“| __l \(['\”](。*)['\“] \)|”,$ content,$ matches,PREG_PATTERN_ORDER);对那些感兴趣的人。 – lukaserat