UTF-8 Encoding of Pound Sign PHP [duplicate] - php

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 6 years ago.
I'm creating a messaging system with PHP and MySQL but am having problems when certain characters are entered. Particularly the Pound sign (£).
The form where users write their message is POSTed to a PHP script with the following functions:
$message = htmlspecialchars($message, ENT_QUOTES);
$message = utf8_encode($message);
Then $message is INSERTed into a Database where it is stored in a Text Column.
However, when inputing a Pound sign no data appears in the database at all on my live server, but on my localhost (using MAMP) £ appears in the database.
Anybody know whats going on? And is there a way to encode £ as £, I feel like that might solve my issue.

If your database encoding is not UTF-8, or if the application does not retrieve data from the database as UTF-8, data stored in the database will not render correctly.Check your db encoding please and if this is not the problem put this to your php page
header('Content-Type: text/html; charset=utf-8');

Related

php echo showing question marks instead of arabic letters [duplicate]

This question already has answers here:
How do I send emails with Arabic content via PHP's mail function?
(4 answers)
UTF-8 all the way through
(13 answers)
Closed 5 years ago.
I use PHP (echo) to add user session data to the HTML page and it worked fine on one server but when I moved to another one it shows Arabic data in question marks like this (???). how to fix this?
NOTE 1: Arabic data added in the html page using HTML or JAVASCRIPT or AJAX call from database is showing correctly. it only shows question marks when using PHP echo command.
update: the first duplicate is about setting up a server but I'm using a shared webhosting. the second one is about sending email and changing the header didn't work for me.
UPDATE: looks like it was a problem while restoring the database to the new server. new entered data is showing correctly while old ones are messed up!

MYSQL texts looking weird [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 7 years ago.
I am making an android application that sends some TEXT to server and other people can see those Text but the problem is here when I send the TEXT it looks like this (سلام به همه) in the MYSQL table inside the server and it shows the text like this (???????????) (By the way I am writing the text in Persian) to the people who get the text and also when I add some records manually inside the database it also shows like question marks on the PHONE.
I tried puting database and tables Collation to utf8_general_ci and utf8_persian_ci but it did not work.
How do you send the data to the server, is it via a PHP Service? If so, I once had a problem with Cyrillic and setting the connection itself to UTF8 helped.
Here's the statement if you are using mysqli but I think there's an alternative for PDO as well.
mysqli_set_charset($con,"utf8");

php search function not displaying the correct encoding [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 8 years ago.
I'm building a php search page for a photo gallery to pull data with Chinese characters from MySQL.
I've done the following:
1. setting webpage to utf-8 encoding meta http-equiv="content-type" content="text/html";charset="utf-8"
2. ensure that the collation for mysql db and data itself is utf8_general_ci
3. set chrome encoding to utf-8.
But when I put in a positive search string to pull data with Chinese characters, they always come up as ???
I've checked my php array raw output and it is also ??? which leads me to believe there is something wrong at my database end. But I need to add is my gallery page (where the search box is embedded) displays the Chinese characters correctly from the same database.
Have you also set $mysqli->set_charset('utf8'); ?

When i inserted string "Jack - Jill" in mysql db it saved as "hello – world" [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Insert into a table which has a dash in the name
(4 answers)
Closed 8 years ago.
While inserting data "Jack - Jill" in mysql db, it saving as "Jack †Jill“, my problem is when i tried to display the string in page its showing like "Jack �€� Jill", i am just botherd to display the string properly like "Jack - Jill", i tried have proper charactersets but not much of luck.
make sure you specify the charset used by your page to the database (and all its tables), and the other way around. i.e.:
Give your page a metatag and the script witing to the database a line that either validates that the charset is UTF-8 (example charset), or that it converts the chaarset to UTF-8
and give your database the same property, that it saves and reads data as UTF-8 (i use PHPMyAdmin, if you use such GUI tools too, its just a checkbox away).
hope i pointed you into the right direction

How are arabic letters (correctly) stored in mysql ? ب or ب [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 9 years ago.
This might be a dummy question, but I'm a little lost in it.
How are Arabic questions exactly stored in a database ?
Let's take ب, if I insert that directly in the DB it becomes ?. Not good.
If I use a form (and php script) and store it as UTF-8, it is stored like ب. I can read it out and print it out, all good.
So my question is, are Arabic (and Japanese,...) letters always stored likes this in a mysql database ب ? Or should I change a setting somewhere and it should look like ب when I'm browsing the database?
It's just to define the length of my rows (varchars/chars) in the database...
DB set to utf8_general
Site fully UTF8
If you try to store a UTF-8 encoded character and it becomes ?, this means MySQL did not understand or support the encoding in which you sent the character. The column needs to be set to store utf8 data (better utf8mb4 if supported) and the connection encoding needs to be set to the correct encoding to inform MySQL in what encoding you're sending data to it.
If you get HTML entities from a form submission, this means the browser tried to send data in an encoding which did not support that particular character; therefore it had to fall back on HTML entities to encode the character. You need to set the encoding declarations correctly to tell the browser it should send UTF-8 encoded text to the server.
See Handling Unicode Front To Back In A Web App and/or UTF-8 all the way through for how to do all this.

Categories