In PHP manual given example is
echo substr_compare("abcde", "bcg", 1, 2); // 0
I tested the code and get the same result, but how “bc” and “bcg” can be equal? This should give -1. Am I missing something here?
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.
Read the documentation carefully:
You compare up to 2 characters from position 1 in
main_str("abcde"), which is"bc", with"bcg". But only up to 2 characters.See also about the
lengthparameter:I agree it could be misunderstood, but only up to
lengthcharacters are compared.