views:

162

answers:

2

This is the regex i'm trying to use:

/^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/gim

I found it on this site, and it works great when i try it out there. But as soon as i place it in my code i get this message:

Warning: preg_match() [function.preg-match]: Unknown modifier 'g' in C:\xampp\htdocs\swebook\includes\classes.php on line 22

Can anyone explain what's wrong, and why it's working on that website and not in my code?

Thanks a bunch!

A: 

Remove the g in gim at the end - php does not have the global modifier because the functions you call decide if it is global or not.

Jasper
Oh, thanks. They should put an option on that site that makes it "PHP safe" so people that don't know so much about it will be able to use it as they want to. Hehe.
Nike
+4  A: 

There is no modifier g for preg_match. Instead you preg_match_all function.

So instead of:

preg_match(/^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/gim,....)

use:

preg_match_all(/^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/im,....
codaddict