I have a string and I need to see if it contains the following “_archived”.
I was using the following:
preg_match('(.*)_archived$',$string);
but get:
Warning: preg_match() [function.preg-match]: Unknown modifier '_' in /home/storrec/classes/class.main.php on line 70
I am new to Regular Expressions so this is probably very easy.
Or should I be using something a lot simpler like
strstr($string, "_archived");
Thanks in advance
strstr is enough in this case, but to solve your problem, you need to add delimiters to your regex. A delimiter is a special character that starts and ends the regex, like so:
The delimiter can be a lot of different characters, but usual choices are /, # and !. From the PHP manual:
Read all about PHP regular expression syntax here.
You can see some examples of valid (and invalid) patterns in the PHP manual here.