How do I know the string is mb string? so we use mb_strlen instead of strlen ?
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.
You need to always know what encoding a string is in, and whether it is a multibyte one. After all, you need to pass the string’s encoding as the second parameter to
mb_strlen()to get reliable results, right?The encoding of incoming data will always be defined in some way – the page’s encoding when processing form data; the database connection’s and tables’ encoding when processing database data; and so on. It is your job to build the flow in a way that you always know what is in what encoding where.
The only exception is when you’re dealing with arbitrary third party data that don’t declare their content’s encoding properly. It is then (and only then) when it’s okay to employ sniffing functions like
mb-detect-encoding()and colleagues. Remember that those functions are very error-prone and can give you only an educated guess what encoding a string is in, not hard reliable info.