3
Using preg_replace() in PHP, I came across the following situation:
echo preg_replace('/:([\w]+)/', 'batata', ':quiabo/isso/:nada');
echo preg_replace('@:([\w]+)@', 'batata', ':quiabo/isso/:nada');
Both expressions print the same thing: potato/it/potato
From that I have two doubts:
1 - Why we need to use '/' or '@' at the beginning of Pattern?
2 - What is the difference between using '/' or '@' in this same situation?
You can also use
~
, I think it’s more readable depending on the ER.– Papa Charlie
Or
#
or%
, or~
, etc..– Guilherme Nascimento