swampone Posted September 11, 2010 Share Posted September 11, 2010 A user submit a comment to my database. If the user comment includes a word that has "" it stops the rest of the comment from being printed. I guess it has to be escaped somehow. $info = "this is a "testing" comment"; echo $info; //This will only print: this is a //I need it to print everything: this is a "testing" commentecho $info; Quote Link to comment https://forums.phpfreaks.com/topic/213103-the-whole-string-not-being-printed/ Share on other sites More sharing options...
mikosiko Posted September 11, 2010 Share Posted September 11, 2010 A user submit a comment to my database. If the user comment includes a word that has "" it stops the rest of the comment from being printed. I guess it has to be escaped somehow. $info = "this is a "testing" comment"; echo $info; //This will only print: this is a //I need it to print everything: this is a "testing" commentecho $info; You can't figure out why?..... just look your $info variable and the what is printing.... what do you think is happening? Quote Link to comment https://forums.phpfreaks.com/topic/213103-the-whole-string-not-being-printed/#findComment-1109827 Share on other sites More sharing options...
swampone Posted September 11, 2010 Author Share Posted September 11, 2010 I see that. But that's the way its stored in the database. Im finding that users want to put words in quotes. Quote Link to comment https://forums.phpfreaks.com/topic/213103-the-whole-string-not-being-printed/#findComment-1109829 Share on other sites More sharing options...
fortnox007 Posted September 11, 2010 Share Posted September 11, 2010 swampone, I am still a novice but I think i can solve this for you in php you can have a string with double quotes or with single quotes. And here docs but that's not interesting now. If you start a string with double quotes and want to display double quotes on output you must escape the double quotes. ie $string = "i am a \"fat\" monkey"; If you start a string with single quotes and want to display single quotes on output you must escape the single quotes. ie $string = 'we are "fat" monkey\'s'; Quote Link to comment https://forums.phpfreaks.com/topic/213103-the-whole-string-not-being-printed/#findComment-1109830 Share on other sites More sharing options...
joel24 Posted September 11, 2010 Share Posted September 11, 2010 You can't figure out why?..... just look your $info variable and the what is printing.... what do you think is happening? Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime. Staying true to your signature I see Back on the topic... Take a look at $info = "this is a "testing" comment"; the quotations in "testing" are closing the original quotations around the string and so only "this is a " is being echoed check out this tutorial and then look at this Quote Link to comment https://forums.phpfreaks.com/topic/213103-the-whole-string-not-being-printed/#findComment-1109832 Share on other sites More sharing options...
mikosiko Posted September 11, 2010 Share Posted September 11, 2010 Staying true to your signature I see always trying Quote Link to comment https://forums.phpfreaks.com/topic/213103-the-whole-string-not-being-printed/#findComment-1109833 Share on other sites More sharing options...
fortnox007 Posted September 11, 2010 Share Posted September 11, 2010 me too haven't found any monkeys though to robe banks for me : ) Quote Link to comment https://forums.phpfreaks.com/topic/213103-the-whole-string-not-being-printed/#findComment-1109834 Share on other sites More sharing options...
joel24 Posted September 11, 2010 Share Posted September 11, 2010 me too haven't found any monkeys though to robe banks for me : ) *rob Typo is in your signature also... Quote Link to comment https://forums.phpfreaks.com/topic/213103-the-whole-string-not-being-printed/#findComment-1109836 Share on other sites More sharing options...
mikosiko Posted September 11, 2010 Share Posted September 11, 2010 I see that. But that's the way its stored in the database. Im finding that users want to put words in quotes. Back To Topic: If you are talking about storing fields in the database with special characters on them, you should read about mysql_real_escape_string(), addslashes(), and stripslashes() at minimum in a direct string as the one that you showed the additional " need to be escaped... "this is a \"testing\" .... etc... " Quote Link to comment https://forums.phpfreaks.com/topic/213103-the-whole-string-not-being-printed/#findComment-1109838 Share on other sites More sharing options...
swampone Posted September 11, 2010 Author Share Posted September 11, 2010 I am still having trouble with this, so let me see if i can be more clear. A user submits a comment through a html form. The comments makes it to the database, no problem, even if a user decide that they want to use double quotes on some of the words in their comment. The problem occurs when I pull the comment from the database and the user used double quotes in there comment, this is where i get the break in the comment. $query = "SELECT * FROM post"; $result = mysql($query); while($row = mysql_fetch_array($result)){ $comment = stripslashes($row["comment"]); echo $comment; } This works fine if a user submits a comment that doesn't contain the double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/213103-the-whole-string-not-being-printed/#findComment-1109862 Share on other sites More sharing options...
jcbones Posted September 11, 2010 Share Posted September 11, 2010 Run the string through htmlentities(). This should solve your problem. Quote Link to comment https://forums.phpfreaks.com/topic/213103-the-whole-string-not-being-printed/#findComment-1109903 Share on other sites More sharing options...
swampone Posted September 11, 2010 Author Share Posted September 11, 2010 Thanks! htmlentities() worked perfectly Quote Link to comment https://forums.phpfreaks.com/topic/213103-the-whole-string-not-being-printed/#findComment-1110010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.