The solution (other answers do not mention "mdash", at least during my initial writing) is that when PHP refers to delimiters, this does not apply to delimiters that you see in your code (which are quotation marks ) but the following characters are inside the string. (Actually, I have never seen this anywhere in any documentation: you should see it in the examples.) Therefore, instead of the regular expression syntax, as you are used to many other languages:
/something/
PHP uses strings and then looks at the string for another :
'/something/'
The PHP delimiter refers to a pair of characters / instead of a pair of characters ' . Therefore, if you write 'something' , PHP will take s as the intended delimiter and complains that you are not allowed to use alphanumeric characters as the delimiter.
So, if you want to pass (for example) i to show that you want a match with the registration, you pass it inside the string, but outside the regular expression delimiters:
'/something/i'
If you want to use something other than / as a separator, you can, for example, if you match the URL and don't want it to remove all slashes:
'~something~'
iconoclast Apr 02 '14 at 15:23 2014-04-02 15:23
source share