2011-08-04 60 views
0

我的PHP代碼行,我需要改變替換的preg_match()語法錯誤eregi()

while (eregi("([-]?)\"([^\"]+)\"", $a, $regs)) { 

while (preg_match("([-]?)\"([^\"]+)\"", $a, $regs)) { 

if (strlen($word) < $min_word_length || (!eregi($pattern, remove_accents($word))) || ($common[$word] == 1)) { 

if (strlen($word) < $min_word_length || (!preg_match($pattern, remove_accents($word))) || ($common[$word] == 1)) { 

我嘗試了所有可能的(我可以)組合,我在谷歌搜索和這裏也找不到。

+0

你沒有使用分隔符....你可以看到手冊http://www.php.net/manual/en/regexp.reference.delimiters.php。試試這個」 /([ - ]?)\ 「([^ \」] +)\ 「/」 – laurac

+0

@laurac感謝您的建議,您的書面線只是工作完美。你能否寫下第二行呢? – Anuj

+0

檢查答案:) – laurac

回答

1

你沒有使用分隔符.... 你可以看到手冊php.net/manual/en/regexp.reference.delimiters.php。 (/ - []])/「(」我只在字符串的開頭和結尾添加「/」/ $模式/「)

if (strlen($word) < $min_word_length || (!preg_match("/$pattern/", remove_accents($word))) || ($common[$word] == 1)) { 
+0

對不起,這麼晚回覆。但你很棒,爲我節省了很多時間。非常感謝你。 – Anuj