PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've got a form that sends text to the attached PHP script that subsequently submits the text to a mySQL database. I'd like to convert all the right single quotation marks ’ featured within the text into apostrophes '. I've experimented with the attached code but it doesn't seem to work. I've also tried swapping the characters' HTML equivalents in the same fashion but it didn't work either.
It could be because you're escaping the string with mysql_real_escape_string() and then replacing the single quote marks. This will cause an error in your SQL statement as you'll have unescaped quotes in there:
choppsta wrote:It could be because you're escaping the string with mysql_real_escape_string() and then replacing the single quote marks. This will cause an error in your SQL statement as you'll have unescaped quotes in there:
I think if you swap these round so you do the replace first it should solve your problem.
I've tried doing the following, is this what you meant? It still fails to swap the characters. I think it might be something to do with the particular characters I'm trying to swap. For example if I try to swap all instances of the word "cat" into the word "dog" it does work.
Sounds like what you think is a single quote mark is actually another character. Have you tried copy and pasting the character you want to replace into your code? Depending on what editor you're using it might be worth a shot?
Jenk wrote:Have you tried echo'ing $leaostext, or your final query to see the what the output is?
The output is the text $leaostext with the right single quotation marks still present.
choppsta wrote:Sounds like what you think is a single quote mark is actually another character. Have you tried copy and pasting the character you want to replace into your code? Depending on what editor you're using it might be worth a shot?
I've being copying and pasting the character I want to replace into my code from the beginning, I've also tried using the character's HTML equivalent: & #8217; (N.B. I separated '&' from '#' in this example so that the forum wouldn't translate the code immediately into its equivalent character.)