2013-08-26 68 views
0

爲什麼這不起作用(既不匹配也不),它似乎不解析它。PHP:[[:<:]] and [[:>:]]錨

<?php 
echo preg_match("/[[:<:]]name[[:>:]]/","my name is max"); 
?> 

它不輸出既不0也不1。爲什麼?

+0

您的代碼可能返回false。 [手動](http://www.php.net/manual/en/function.preg-match.php#refsect1-function.preg-match-returnvalues)說:* ...或錯誤發生時爲FALSE *你的代碼是否給出了錯誤? – MisterBla

+0

你想要匹配什麼? – silkfire

回答

0

您好像關閉了錯誤報告功能。如果你必須啓用它,你會得到以下錯誤:

Warning: preg_match(): Compilation failed: unknown POSIX class name at offset 3 in ...

這意味着你不能有一個類的名稱,包括小於號([[:<:]])的;改爲給它一個適當的名字。

0

嘗試是這樣的

<?php 
echo preg_match("/name/","my name is max"); 
?> 
+0

我試圖找出那個錯誤。我知道你的方式匹配。 :-) – sl34x

0

你有一個錯誤:編譯失敗:未知的POSIX類名的偏移量爲3

+0

我怎樣才能看到它是否返回錯誤? – sl34x

+0

這不是致命錯誤,只是警告。 –