im new to regular expressions and would like to decipher this.
return preg_replace("/[<>]/", '_', $string);
thanks!!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It means “replace each
<or>inside the string$stringwith an underscore, then return the result”.The slashes (
/) delimit the regular expression. You can use other characters instead (preg_replace("#[<>]#", '_', $string);would work just as well and makes sense if your regex contains a slash itself).[]brackets denote a character class. They mean essentially “one character of those contained within the class”, so[<>]means “either a<or a>“.You can also negate a character class by starting it with a
^:[^<>]means “any character except<or>.