I was wondering how can I convert user submitted data that contains an & to and using PHP before its stored in the database.
I was wondering how can I convert user submitted data that contains an &
Share
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.
Use
str_replaceNote that this will perform a straightforward replacement, hence (as seen on ideone.com):
If you want to insert spaces when there previously wasn’t, then you may want to use regular expressions function like
preg_replaceas follows:The pattern
\s*is the regex pattern for “zero or more” (*) of whitespace characters (\s). In other words, this will replace&, including any preceding and following whitespaces (of any length), and replace it with' and '.