Special characters in PHP / MySQL
Changed the HTML charset to ISO-8859-1 fixed the problem! Silly
Special characters showing up on content retrieved from mysql using php
Try setting the utf8 charset at the PDO Connection like this:
$pdo = new PDO(DSN, USER, PASSWORD,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
PHP allow special characters from MySQL query column in Array
What solved the issue was amending:
$data = $row;
to:
$data[] = array ( 'ID' => $row['ID'], 'UserID' => $row['UserID'], 'MessageText' => nl2br(htmlentities($row['MessageText'],ENT_COMPAT|ENT_IGNORE, "UTF-8") ), 'cntLikes' => $row['cntLikes'], 'Type' => $row['Type'] );
The database column that was stopping the array from pulling back was 'MessageText'. This column had originally come from an Excel spreadsheet where the data was very dirty.
Using
nl2br(htmlentities($row['MessageText'],ENT_COMPAT|ENT_IGNORE, "UTF-8"))
resolved the issue.
PHP SQL find ™ and other special characters
Thanks to Rick and Nl-X
Turns out that in the
<?php require_once(' dB connection....
it was PDO which would not allow the encoding to be changed.
So solution add a
$conn2=mysqli_connect($servername,$username,$password,.......
$search_what = 'Table_Name';
$Search_for2 = '™';
$Search_for = '%'.$Search_for2.'%';
$Replace_with = 'TRADE MARK';
SearchToSee($conn2,$search_what,$Search_for,$Replace_with,$Search_for2);
and the function
function SearchToSee ($conn2,$search_what,$Search_for,$Replace_with,$Search_for2) {
mysqli_set_charset($conn2, 'utf8'); // change as required
mysqli_query($conn2, "SET NAMES 'utf8';");// change as required
mysqli_query($conn2, "SET CHARACTER SET 'utf8';");// change as required
mysqli_query($conn2, "SET COLLATION_CONNECTION = 'utf8_unicode_ci';"); // change as required
// below makes it simple to see what your changing
$result = mysqli_query($conn2, "SELECT * FROM $table WHERE $search_what Like '$Search_for'");
$result2 = mysqli_query($conn2, "select
@@collation_server,
@@collation_connection,
@@character_set_server,
@@character_set_client;");
foreach ($result2 as $grr) {
echo '<br>';
print_r ($grr);// shows result of new settings need to match last line
echo '<br>Array ( [@@collation_server] => latin1_swedish_ci [@@collation_connection] => latin1_swedish_ci [@@character_set_server] => latin1 [@@character_set_client] => latin1 ) '; // original N/W $grr
echo '<br>latin1_swedish_ci ---- utf8_general_ci ---- latin1 ----- utf8 <br><br>'; // from @@ checks in phpmyadmin on table.
}
// TO Update
mysqli_query($conn2, "UPDATE Table_Name SET $search_what = replace($search_what, '$Search_for2', '$Replace_with') WHERE $search_what Like '$Search_for'");
}
Hope that helps someone.
MySQL Wildcard Filtering Special Character using LIKE
Your problem is that somehow you have managed to get an actual backslash in the value in the database, so you need to search for that. Try this:
SELECT * FROM listings WHERE title LIKE '%Debbie\\\\\'s Pet Grooming%'
Demo on dbfiddle
From the manual:
Because MySQL uses C escape syntax in strings (for example, “\n” to
represent a newline character), you must double any “\” that you use
in LIKE strings. For example, to search for “\n”, specify it as “\\n”.
To search for “\”, specify it as “\\\\”; this is because the
backslashes are stripped once by the parser and again when the pattern
match is made, leaving a single backslash to be matched against.
Related Topics
How to Retrieve Utf-8 Accented Characters from Access via Pdo_Odbc
Find Common Values in Multiple Arrays with PHP
Using Strtotime for Dates Before 1970
How to Implement Pagination in PHP
Undefined Variable Problem with PHP Function
Binding Parameters for Where in Clause with Pdo
Google_Service_Directory - (403) Not Authorized to Access This Resource/Api
Is Include()/Require() with "Side Effects" a Bad Practice
Post Form and Update Multiple Rows with MySQL
PHP Array Behaving Strangely with Key Value 07 & 08
PHP Add Element to Every Sub Array of Multi Dimension Array
Confusing About This Cookies in Redirecting System
Interface or an Abstract Class: Which One to Use
PHP Expects T_Paamayim_Nekudotayim