I use the code below to replace these funky characters when they end up in the database. In phpmyadmin the queries work just fine, however, when I use something similar in php, they don't throw any errors and they also don't work.
In mysql: -
UPDATE news SET title=(replace (title, '’','\''));
-
UPDATE news SET description=(replace (description, '’','\''));
-
UPDATE news SET title=(replace (title, '‘','\''));
-
UPDATE news SET description=(replace (description, '‘','\''));
-
UPDATE news SET title=(replace (title, ''','\''));
-
UPDATE news SET description=(replace (description, ''','\''));
-
UPDATE news SET title=(replace (title, '&','\&'));
-
UPDATE news SET description=(replace (description, '&','\&'));
-
UPDATE news SET title=(replace (title, '–','-'));
-
UPDATE news SET description=(replace (description, '–','-'));
-
In php: -
$find[] = '“'; // left side double smart quote
-
$find[] = '”'; // right side double smart quote
-
$find[] = '‘'; // left side single smart quote
-
$find[] = '’'; // right side single smart quote
-
$find[] = '…'; // elipsis
-
$find[] = '—'; // em dash
-
$find[] = '–'; // en dash
-
-
$replace[] = '"';
-
$replace[] = '"';
-
$replace[] = "'";
-
$replace[] = "'";
-
$replace[] = "...";
-
$replace[] = "-";
-
$replace[] = "-";
-
-
$cleanQuery = "SELECT * FROM news ORDER BY id DESC LIMIT 50";
-
$runSelect = mysql_query($cleanQuery) or exit(mysql_error().$cleanQuery);
-
while($tickerResults = mysql_fetch_assoc($runSelect)) {
-
$saveWeather = "UPDATE news SET title = '".mysql_real_escape_string(str_replace($find, $replace, $tickerResults['title']))."', description = '".mysql_real_escape_string(str_replace($find, $replace, $tickerResults['description']))."' WHERE id = '".$tickerResults['id']."'";
-
//exit($saveWeather);
-
$runInsert = mysql_query($saveWeather) or exit(mysql_error().$saveWeather);
-
}
-
What am I doing wrong here?
4 3420
as this is a character set problem, you should rather find the reason why it changes the encoding. for instance you might not have configured the DB connection to use UTF-8.
I'm parsing in rss feeds, at which point the characters are turned into that mess by php... This has really boggled me for a while now.. I've tried a few utf-8 conversion attempts with no success.
U have to convert your DB into UTF-8. And try to save all the entries again. This would save different language data properly.
Also, on the site, you can put language code in META TAB. So, it would show that language data properly on web page.
PHP dont make mess with encoding at all. I have to deal with Japanese language with two different encoding. UTF-8 for normal website and shift-jis for mobile web-site.
You better make sure you are not mixing encoding. And use a good text editor.
And yes Database is configured for UTF-8. But I think even if the database base is configured as UTF-8. But you can save different Encoding in the table. Cause whatever encoding you use its all binary data and size is divisible by 8 with no carrige.
And to replace escape character use mysql_real_escape_string it will save your energy
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Scot Hacker |
last post by:
I have a database that has been populated with content pasted out of MS
Word, and is full of special characters -- em dashes, curly quotes, curly
apostrophes, etc. Now I'm generating plain text...
|
by: Marian Aldenhvel |
last post by:
Hi,
I am very new to Python and have run into the following problem. If I do
something like
dir = os.listdir(somepath)
for d in dir:
print d
The program fails for filenames that contain...
|
by: Nicholas |
last post by:
How can I compare char* with integers and characters contained in the str,
where integers can be one digit or more?
void Access(char *str) {
char *pt = str;
while (pt != '0') {
if...
|
by: Guadala Harry |
last post by:
I'd like to know the answer to the following question so I can know what to
expect with regard to other similar uses of escape characters and strings.
While everything works fine - I'd like to know...
|
by: Fred Nelson |
last post by:
Hi:
I'm writing an error handling system for my vb.net windows application. I
have an error trapping routine that is catching all unexpected errors,
writing an entry in an sql database and...
|
by: Lad |
last post by:
Can anyone give an example how to send email with non-ascii characters(
both in subject and body).
I would like to use windows-1250 code page
Thank you
L.B.
|
by: comp.lang.php |
last post by:
I have a textarea where people can cut & paste their resume.
Unfortunately they often cut & paste their Word resume into the
textarea, funky characters and all.
This causes the display to be...
|
by: Thorsten Ottosen |
last post by:
Hi,
I'm trying to escape html before its saved in a database.
I tried
$text = htmlentities( $reader->value );
but that don't work for e.g. japanese characters.
|
by: Gerry Vandermaesen |
last post by:
Hi all,
What would be the best way to encode and optimally also compress a long
string with URL unsafe characters to be passed as a GET parameter?
Example string:
...
|
by: webqueen79 |
last post by:
When I open up my asp code in an editor, I see TONS of extra whitespace between code lines which is making the editor bomb out because it takes so long to load all the lines. When I open up the asp...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |