I am confused with following string function
echo strlen("l\n2"); //give 3 in output
where as
echo strlen('l\n2'); //give 4 in output
can anybody explain why ?
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.
Because when you use single quotes (‘ ‘), PHP does not expand the
\nas a single new line character whereas in double quotes (” “),\ntranslates to the new line character (ie. a single character) thus giving 3 charactersTaken from PHP’s String Documentation: http://php.net/manual/en/language.types.string.php