2015-04-06 49 views
-1

請問您能解釋一下這個preg_match代碼在做什麼! 我也不明白爲什麼它以#標籤開頭?用#hash解釋preg_match語法

if (!preg_match('#\.(.+)$#', $file['name'][$key], $matches)) {..;} 
+0

pcre讓你選擇你想要劃定模式的字符,就這些了。在這種情況下,它是'#foo#',而不是'/ foo /' –

回答

0

首先,它測試,如果正則表達式不匹配!preg_match)以下:

#\.(.+)$# 
--------- 

Match the character 「#」 literally «#» 
Match the character 「.」 literally «\.» 
Match the regex below and capture its match into backreference number 1 «(.+)» 
    Match any single character that is NOT a line break character (line feed) «.+» 
     Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» 
Assert position at the end of a line (at the end of the string or before a line break character) (line feed) «$» 
Match the character 「#」 literally «#» 

我不能幫你$file['name'][$key],因爲我不知道它是什麼,它似乎是一個filename