473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

What should I do with funky '’' characters?

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:
Expand|Select|Wrap|Line Numbers
  1. UPDATE news SET title=(replace (title, '’','\''));
  2. UPDATE news SET description=(replace (description, '’','\''));
  3. UPDATE news SET title=(replace (title, '‘','\''));
  4. UPDATE news SET description=(replace (description, '‘','\''));
  5. UPDATE news SET title=(replace (title, ''','\''));
  6. UPDATE news SET description=(replace (description, ''','\''));
  7. UPDATE news SET title=(replace (title, '&','\&'));
  8. UPDATE news SET description=(replace (description, '&','\&'));
  9. UPDATE news SET title=(replace (title, '–','-'));
  10. UPDATE news SET description=(replace (description, '–','-'));
  11.  
In php:
Expand|Select|Wrap|Line Numbers
  1. $find[] = '“'; // left side double smart quote
  2. $find[] = '”'; // right side double smart quote
  3. $find[] = '‘'; // left side single smart quote
  4. $find[] = '’'; // right side single smart quote
  5. $find[] = '…'; // elipsis
  6. $find[] = '—'; // em dash
  7. $find[] = '–'; // en dash
  8.  
  9. $replace[] = '"';
  10. $replace[] = '"';
  11. $replace[] = "'";
  12. $replace[] = "'";
  13. $replace[] = "...";
  14. $replace[] = "-";
  15. $replace[] = "-";
  16.  
  17. $cleanQuery = "SELECT * FROM news ORDER BY id DESC LIMIT 50";
  18. $runSelect = mysql_query($cleanQuery) or exit(mysql_error().$cleanQuery);
  19. while($tickerResults = mysql_fetch_assoc($runSelect)) {
  20.     $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']."'";
  21.     //exit($saveWeather);
  22.     $runInsert = mysql_query($saveWeather) or exit(mysql_error().$saveWeather);
  23. }
  24.  
What am I doing wrong here?
Aug 18 '10 #1
4 3420
Dormilich
8,658 Expert Mod 8TB
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.
Aug 20 '10 #2
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.
Aug 21 '10 #3
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.
Aug 21 '10 #4
johny10151981
1,059 1GB
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
Aug 21 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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...
11
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...
13
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...
3
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...
1
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...
7
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.
12
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...
10
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.
1
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: ...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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
0
BarryA
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...
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.