My spaces in text field get stored in mysql DB as ' name ' which was just like ' name ' in UI. But when i display it to screen it gets displayed properly. but when i get count of the variable like strlen($var) it gives me count as 8 instead of 6. So any thing wrong like the way i am doing?
My spaces in text field get stored in mysql DB as ‘ name ‘
Share
This has all the hallmarks of a charset mismatch. This happens if your database is, for example, using an encoding of UTF8, but your web application is using an encoding of LATIN1. I’d suggest double-checking that the same encoding scheme is used throughout both your database tables and your application code. Also make sure that a SET NAMES query is run to explicitly set the charset.
It’s also possible that if you’re connecting directly to the database with a client (SQLYog or somesuch), then that’s using a different encoding and displaying the data differently, even if both the web app in question and the database in question are using the same encoding.
One more thing, strlen doesn’t handle encodings that use more than 1 byte per character very well. You should be using mb_strlen instead.
https://www.php.net/manual/en/function.mb-strlen.php