Akshay Shrivastav Akshay Shrivastav - 3 years ago 143
HTML Question

While fetching values from database the single quotes shows ? icon in HTML

I am making a simple blog model in php for now i have added this data directly in data from phpmy admin this is the dummy data

Post-ironic mumblecore authentic, stumptown try-hard chambray sartorial
McSweeney’s VHS put a bird on it. Pitchfork lomo meggings, meh whatever cred
beard four loko hella. Flannel swag normcore, leggings 3 wolf moon meditation
Marfa hella fingerstache Thundercats mustache. Lo-fi typewriter Shoreditch,
Odd Future fingerstache iPhone retro McSweeney’s four loko Kickstarter hoodie


The above text has
'
single quotes values in it now the problem is when the vales are being parsed in php and then displayed in HTML format it shows � instead of single quote.

What might be the problem?

This is the output i am geeting in html format

Post-ironic mumblecore authentic, stumptown try-hard chambray sartorial
McSweeney�s VHS put a bird on it. Pitchfork lomo meggings, meh whatever
cred beard four loko hella. Flannel swag normcore, leggings 3 wolf moon
meditation Marfa hella fingerstache Thundercats mustache. Lo-fi typewriter
Shoreditch, Odd Future fingerstache iPhone retro McSweeney�s four loko
Kickstarter hoodie


I am using the normal php code to display the data like this
<?php echo $value['post_content']; ?>
i have even tried the
htmlspecialchars_decode
function in PHP but doesn't work well

I am using OOP PHP technique and this is the code i am using

$query = "SELECT * FROM posts";
$connection = $this->establish_connection();
$data = $connection->query($query);
$connection->close();

Answer Source

It is a Unicode problem .

The original text is encoded with different Unicode not that you use to display (utf8) so , try this:

$query = "SELECT * FROM posts";
$connection = $this->establish_connection();
$connection->set_charset("utf8"); 
$data = $connection->query($query);
$connection->close();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download