Page 1 of 1
capturing quotation marks and apostrophes in textarea input
Posted: Thu Dec 21, 2006 3:44 pm
by konstandinos
hello folk
ive got a standard <textarea> that i am using to capture input. the intended input is large(ish) essays, that are made up of paragraphs of writing, which may inclue apostrophes and quotes.
im putting this captured data into my dbase in field of type text. the variable that stores the form's input is a string (in php).
everytime i try add quotes or apostrophes to my textarea and submit, it doesnt work. any idea how i am meant to capture this?
also, for paragraphs, i am typing <p> tags within my essay. is there anyway i can automate paragraphs based on spaces used in the textarea?
sort of like the input box i am using to type this very post.
"
'
etc.
(ive already posted this under client-side. i thought i'd post this here too, since it might be a php issue.)
Posted: Thu Dec 21, 2006 3:48 pm
by John Cartwright
at minimum when inserting data into a databse, you should pass the input through mysql_real_escape_string(),
as for your paragraphs problem, when outputting your content pass it through nl2br()
Posted: Thu Dec 21, 2006 3:51 pm
by konstandinos
ok great. ill use the mysql method you mentioned. also, i will no longer need <p> tags.
but now can i still add other tags like <pre> (which i am using to display code) and <strong> (to make titles) and <em> (to make italic)?
whats the best practise for this?
kinda like the wordpress input box.
Posted: Thu Dec 21, 2006 3:53 pm
by Kieran Huggins
use var_dump() take a look at how the browser is encoding the POST data - that will allow you to reformat things like paragraphs, etc... Regular expressions might help auto-format things like headings, but it won't be perfect.
Alternatives are using pseudo-code (like bbcode or wikicode), or using a rich textarea like
FCKeditor in the client side, then capturing the xhtml it produces.
If you're having issues with things like hyphens, you'll need to learn about character encoding (more specifically, Unicode) and how browsers handle the display and POSTing of different character encodings. It's a big subject, beware! Ultimately, using FCKeditor or one of it's contemporaries would likely skirt that issue, but they have a learning curve as well.
Cheers,
Kieran
Posted: Thu Dec 21, 2006 4:12 pm
by konstandinos
mysql_real_escape_string and nl2br are working perfectly.
and for the occasional bold or italic phrase, i dont mind adding <strong> and <em> tags myself.
but now i only have one issue: when i try use <pre> tags to paste code, if i use nl2br i get an extra line after each line break in my code too. if i dont use the <pre> tags then i loose the indentation.
any suggestions would be appreciated. but thanks anyway for the help thus far.
Posted: Thu Dec 21, 2006 4:26 pm
by Kieran Huggins
Glad the simple solution is working out for you - definitely a better choice if it works.
Maybe you could run the output of nl2br through a function to replace </pre><br/> with </pre>?
Cheers,
Kieran
Posted: Thu Dec 21, 2006 4:27 pm
by John Cartwright
any suggestions would be appreciated
Kieran Huggins wrote:Alternatives are using pseudo-code (like
bbcode or
wikicode), or using a
rich textarea like FCKeditor in the client side, then capturing the xhtml it produces.
I would recommend bbcode, like these forums use
