2012-09-03 50 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