anarchoi Posted April 1, 2008 Share Posted April 1, 2008 i have a stupid problem: i'm echo'ing an entry from my database that has quotes inside it, so it stops at the first quotes because it breaks the textarea's value="$myvar" how can i paste the text with quotes, keeping them intact, inside of a textbox? Link to comment https://forums.phpfreaks.com/topic/99018-pasting-quotes-from-db-inside-a-textarea/ Share on other sites More sharing options...
pocobueno1388 Posted April 1, 2008 Share Posted April 1, 2008 the textarea tag doesn't have a value attribute, you would do this: echo "<textarea>$value</textarea>"; Link to comment https://forums.phpfreaks.com/topic/99018-pasting-quotes-from-db-inside-a-textarea/#findComment-506673 Share on other sites More sharing options...
papaface Posted April 1, 2008 Share Posted April 1, 2008 You should do: echo "<textarea>".htmlentities($value, ENT_QUOTES)."</textarea>"; Link to comment https://forums.phpfreaks.com/topic/99018-pasting-quotes-from-db-inside-a-textarea/#findComment-506681 Share on other sites More sharing options...
thebadbad Posted April 1, 2008 Share Posted April 1, 2008 I'm guessing you're doing this to be able to edit the entry, and then do an UPDATE query. In that case, use htmlspecialchars() and a user defined function unhtmlspecialchars(), to keep the data intact. When echoing from the database, use htmlspecialchars(), and before inserting the data back in, use unhtmlspecialchars: function unhtmlspecialchars($string) { $string = str_replace('&', '&', $string); $string = str_replace('"', '"', $string); $string = str_replace('<', '<', $string); $string = str_replace('>', '>', $string); return $string; } I refuse to use the [ code ] tags, since they break the ampersands Link to comment https://forums.phpfreaks.com/topic/99018-pasting-quotes-from-db-inside-a-textarea/#findComment-506723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.