Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php outputs � instead of -

Tags:

php

for example when i retrieve from database the word program's instead of program's what would be shown is program�s. ' and - changes to �. how can i fix this?

like image 738
noob Avatar asked Nov 26 '25 23:11

noob


2 Answers

The replacement character � (U+FFFD) means that your data is not correctly encoded. You are probably declaring your output as UTF-8 but your database data is not UTF-8 encoded. So you need to convert the data to UTF-8. You can use mb_convert_encoding to do that.

like image 151
Gumbo Avatar answered Nov 28 '25 13:11

Gumbo


Is your data stored as UTF-8? Try executing these queries before you fetch any data:

SET NAMES utf8
SET CHARACTER SET utf8

Also make sure you're setting your page encoding:

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" />
like image 42
karim79 Avatar answered Nov 28 '25 11:11

karim79