A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearpreg_match_all() [function.preg-match-all]: Unknown modifier ']' - page 1
User InfoPosts
preg_match_all() [function.preg-match-all]: Unknown modifier ']'#1
Using a few different patterns but they each come up with this error - so what's wrong?

My shortest one to diagnose is:

$pattern = "<img([^>]*[^/])>";
preg_match_all($pattern, $subject, $matches);


Thanks

posted date: 2008-12-28 11:26:00


Re: preg_match_all() [function.preg-match-all]: Unknown modifier ']'#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-28 11:26:01


Re: preg_match_all() [function.preg-match-all]: Unknown modifier ']'#3
You are lacking the regexp delimiters. Try:$pattern = "#<img([^>]*[^/])>#i";

posted date: 2008-12-28 11:31:00


Re: preg_match_all() [function.preg-match-all]: Unknown modifier ']'#4
A single slash is the default delimiter, which is why the character after it in your original regex was in the error-message.Using the traditional slashes as delimiters and escaping the slash that is not a delimiter would look like this:$pattern = "/<img([^>]*[^\\/])>/";

posted date: 2008-12-28 11:37:00


Re: preg_match_all() [function.preg-match-all]: Unknown modifier ']'#5
That was it, thanks.

posted date: 2008-12-28 11:42:00


Re: preg_match_all() [function.preg-match-all]: Unknown modifier ']'#6
The error was caused by the other ]. PHP takes the first character '<' as the opening delimiter, and then the regex 'stops' at the first '>'. So, it's the ']' after that first '>' which is giving that error message

posted date: 2008-12-28 11:53:00


Re: preg_match_all() [function.preg-match-all]: Unknown modifier ']'#7
Argh. I hate delimiters. They really have no place in a language where the string literal naturally delimits the regex.

posted date: 2008-12-29 05:02:00


Re: preg_match_all() [function.preg-match-all]: Unknown modifier ']'#8
I beg to differ. Being able to choose the delimiters saves you from backslashtitis.

posted date: 2008-12-29 13:45:00


Re: preg_match_all() [function.preg-match-all]: Unknown modifier ']'#9
Just "pattern" instead of "/pattern/" oder "#pattern#" should be enough. " is a perfectly fine delimiter. Modifiers could go in a separate parameter. Delimiters make sense in Perl, where regular expressions are part of the language syntax and not in strings.

posted date: 2008-12-30 07:16:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.