ebolt007 Posted January 10, 2012 Share Posted January 10, 2012 I have a form that people can fill out, and then it echos the string, however right now they can't use single quotes. Below is how I have it settup. $side = '<p>About Me:</p> <ul> <li>Birth Date: October, 23rd, 2010</li> <li>Hometown: Rapid City, SD</li> <li>Height: 4\'</li> <li>Weight: 50lbs</li> <li>Foot Size: 4</li> <li>Favorite Movie: All of the Shrek Movies!</li> <li>Favorite Book: Winnie the Pooh Series</li> <li>Favorite Cartoon Character: Eeyore or Donkey from Shrek!</li> <li>Favorite TV Show: Anything on Animal Planet!</li> <li>Favorite Food: Hay</li> <li>Favorite Pro Sports Team: Rapid City Rush</li> <li>Favorite Mascot: Nugget, of course!</li> <li>Favorite Game: Donkey Kong!<br /> </li> </ul>'; if ($side != NULL){ echo "<div class=\"grid_6\" id=\"tertiary\"> $side </div>"; }else{ } And I would be able to use $side = "whatever I want to write"; because then they would still need to escape the double quotes with \" if they wanted to put in a link or anything. How do I do this with allowing them to just use single quotes when they enter their data so they don't have to \' (escape the single quote)? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/254744-single-quote-inside-string/ Share on other sites More sharing options...
laffin Posted January 10, 2012 Share Posted January 10, 2012 function addslashes Quote Link to comment https://forums.phpfreaks.com/topic/254744-single-quote-inside-string/#findComment-1306264 Share on other sites More sharing options...
ManiacDan Posted January 10, 2012 Share Posted January 10, 2012 Definitely not addslashes, that hasn't been recommended for years. If you're trying to include content inside of HTML tags, you should use the htmlentities() function. Quote Link to comment https://forums.phpfreaks.com/topic/254744-single-quote-inside-string/#findComment-1306267 Share on other sites More sharing options...
laffin Posted January 10, 2012 Share Posted January 10, 2012 addslashes is more appropriate for the content. if you notice all the html tags? Quote Link to comment https://forums.phpfreaks.com/topic/254744-single-quote-inside-string/#findComment-1306284 Share on other sites More sharing options...
ManiacDan Posted January 11, 2012 Share Posted January 11, 2012 Indeed I did, which is why I suggested the html function. Quote Link to comment https://forums.phpfreaks.com/topic/254744-single-quote-inside-string/#findComment-1306318 Share on other sites More sharing options...
laffin Posted January 11, 2012 Share Posted January 11, 2012 Than why suggest html function, that would change all the <li> tags to <li> codes. I seen it as Text that is to be displayed as html, not as text that is to be displayed as html code. Quote Link to comment https://forums.phpfreaks.com/topic/254744-single-quote-inside-string/#findComment-1306634 Share on other sites More sharing options...
ManiacDan Posted January 11, 2012 Share Posted January 11, 2012 It depends on the input and the way the users want the output to be. I was assuming, based on the OP's post, that the users were inputting various strings which would be spit out INSIDE of HTML, rather than the users inputting HTML which would then be output and expected to be formatted. If it's the latter, then no encoding at all is necessary. I bet it's the former though, otherwise misplaced unescaped quotes wouldn't be a problem. Quote Link to comment https://forums.phpfreaks.com/topic/254744-single-quote-inside-string/#findComment-1306657 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.