Knowledgebase

Apostrophes, PHP, and MySQL

Posted by BostonGuru, 09-11-2007, 03:12 PM
I am trying to throw together a quick and simple way for a friend to update his news box on his website without having to go in and edit html. What i did is to just move all his entries into a simple 3 column sql db (headline, body text, and id), and then just give him a quick tutorial on how to add rows in phpMyAdmin. The problem I am having is that when there is that when he types something like "Chris's" it is printed out on the website as "Chris?s". If I view the entry in the sql db, it appears as it should. This also happens with the TM symbol; it looks fine stored in the db, but is a question mark when displayed on the website. Do i need to be specifying a particular format when executing the SELECT query on the website in order to preserve the special characters?

Posted by stdunbar, 09-11-2007, 03:41 PM
No, you need to convert those characters to valid HTML for the character set you're using. There is no TM symbol in most character sets. There is, however, a character &153; that would display the TM symbol on most browsers. As far as the single quote - most likely you are using the Microsoft single quote characters. When displayed in a browser some handle it correctly and many don't. Replace those with either a standard single quote or the string '

Posted by zacharooni, 09-11-2007, 07:36 PM
http://php.net/addslashes

Posted by sandykadam, 09-12-2007, 01:52 AM
Hi, When you enter values in db for updating or inserting then you just add addslashes to variables. For eg. So now it will work properly. it will return values which you have entered in editor.

Posted by Dan L, 09-12-2007, 02:02 AM
http://php.net/mysql_real_escape_string http://php.net/htmlentities The former will take care of making the text MySQL-safe, the latter will convert characters to their html equiv - much like stdunbar explains. Your best bet is to write a quick script to apply the two functions to the text before using phpMyAdmin, or, writing a script to completely automate the process. addslashes isn't the best option since, while it does achieve what you need, it requires stripslashes to be applied when the content is retrieved.

Posted by Azazael, 09-22-2007, 11:59 AM
First off thank you so much for the information, I couldn't for the life of me figure out why I all the sudden had ?'s (it happened after a server upgrade). My question is this. I can get the the ' to appear fine now, but my strings have html in them, which is now showing up instead of being parsed. How can I fix that? ex output string should be



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read
Security concerns (Views: 609)
IMIN/Resell4less (Views: 653)


Language:

Client Login

Email

Password

Remember Me

Search