I have a large dB table where I need to search and replace certain char etc. Some of these are special char.
First I am trying just find before changing the statement to Update replace type.
Below runs ok for
$Search_for = '%apple%';
But fails on Special char
So for this example we will concentrate on the ™ ( as pasted from the field)
$search_what = 'LongDescription';
$Search_for = '%™%';
SearchToSee($conn,$search_what,$Search_for);
and the function
function SearchToSee ($conn,$search_what,$Search_for) {
$stmt = $conn->prepare(" SELECT * FROM table_name WHERE $search_what Like '$Search_for' ");
$stmt->execute();
foreach ( $stmt as $row ) {
print_r ($row);
}
So how do I format the $Search_for =
?
For reason further on and other systems I have to run each find replace char differently and replace with its own different letters.
So Far I have tried:
in PHP myadmin WHERE LongDescription
LIKE '%™%' works !!
in the php:
$Search_for = '%apple%'; works but not special char
$Search_for = '%™%';// Not Working
$Search_for = '%_™%';// Not Working
$Search_for = '™';// Not Working
$Search_for = '%™%';// Not Working
Do I need to change the encoding to pass to SQL ?
Now tried:
$Search_for2 = '™';
$Search_for3 = mb_convert_encoding($Search_for2, 'UTF-8', 'UTF-8');
echo $Search_for3;
$Search_for = '%'.$Search_for3.'%';
Which echo's â„¢ and works for a proper term like "APPLE" but still not special characters.