I have a string like this: $str1 = "mod 1 + mode 2 + comp 1 + toto".
I would like to test if mod 1 is in $str1. I used strpos but this function doesn’t help.
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.
strposreturns the position of the occurrence in the string starting with 0 or false otherwise. Using just a boolean conversion like in the following is a common mistake:Because in this case
strposwill return 0. But 0 converted to Boolean is false:So you need to use a strict comparison:
This is also what the documentation advises: