2012-09-03 52 views
0

我需要你的帮助,我不能自己做模式。PHP Preg_match_all正则表达式模式

我获得了该文件:

description1="SIOUH : Authentification Cerbere - Acces" 
    description2="Acces formulaire authentification SIOUH" 
    addheader="Pragma: no-cache " 
    method="get" 
    url="${AUTH_URL}/login/LoginDispatchAction.do?appId=${APP_ID}&backURL=${APP_URL_ENC}" 
    errormessage="Phase 1 : Impossible atteindre le formulaire authentification CERBERE pour SIOUH" 
    serveur="yes" 
    verifypositive="loginConnectAppliForm" 
    logrequest="yes" logresponse="no" /> 

我有这个preg_match_all这完美的作品:

preg_match_all ('#(.*?)="(.*?)"#s', $contents, $matches, PREG_SET_ORDER); //Chaque option 

我的问题是,我可以有简单的报价,而不是双,如何将我的模式改变处理它? 例如,我需要赶上该行的所有其他人一样:

parseresponse='name="conversationId" value="|"' 

感谢很多的帮助。

回答

1

使用反向引用,要求结束引号匹配开一个:

'#(.*?)=([\'"])(.*?)\2#' 
+0

完美! (?*?)=(?:(?:\'(。*?)\')|(?:“(。*?)”))#'但是可以做到这一点你们比较好,谢谢! – timmalos

1

尝试使用正则表达式liek这个

^(.*?)=[\'"](.*?)[\'"]$ 
+0

,我可以有[logrequest = “是” logresponse =“是“]在1行,我不能使用^和$我nmy正则表达式。如果我使用[\ ' “]代替我的”,我得到这个:数组 ( [0] => parseresponse =' 名称=” [1] => parseresponse [2] =>名称= ) 因为我在我的简单报价(parsereponse是一种模式)中得到了一个双引号,所以我们不应该这样做。 – timmalos

+0

然后尝试使用贪婪捕获 - 从第二组圆括号中删除? – BSen

+0

使用'#(\ w *? )= [“\'](。*)[”\']#'我遇到了同一行上的[logrequest =“yes”logresponse =“yes”]的问题 – timmalos