php - Display accented characters
Get the solution ↓↓↓In command line, sqlite correctly displays the accented characters contained in my database. In PHP, echo shows me correctly as well.
But when I do a query from my PHP page, it does not display correctly. I can not find where the encoding problem is.
Thank you in advance for your help.
<?php
$db = new SQLite3('database.sqlite');
if(isset($_GET['search'])) {
$rec = htmlentities($_GET['search']);
} else {
$rec = '';
}
$result3 = $db->query('SELECT lastname,firstname,phone,location FROM rh WHERE name != "" AND lastname || " " || firstname || " " || location LIKE "%'.$rec.'%" ORDER BY name asc LIMIT 25');
?>
The HTML form :
<form action="" method="get">
<input type="search" name="search" value="<?php echo $rec; ?>" /> <input type="submit" value="Search" />
</form>
And the results on another php page :
<?php
echo '<h3>Results</h3>';
echo '<tr><th>Name</th><th>Phone</th><th>Location</th></tr>';
while ($row = $result3->fetchArray(SQLITE3_ASSOC)) {
echo '<tr><td>' . $row['lastname'] . ' ' . $row['firstname'] . '</td><td>' . $row['phone'] . '</td><td>' . $row['location'] . '</td></tr>';
}
$db->close();
?>
Answer
Solution:
Maybe you need to specify the propper encoding in your HTML-Head e.g.:
<html>
<head>
<meta charset="utf-8">
...
</head>
And/or you need to de/encode your data before outpututf8_encode();
.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.