Entry
Is there any way to convert a user's textarea entry into HTML (mostly paragraph formatting)?
Oct 28th, 2001 18:24
Trevor Denham, Mike Boucher, Mark, Wayne Hunt,
the user's input will be stored in the variable name that you put for
the textarea name. Let's assume you called the name of the
textarea
"input". The $input variable in php will store the user's entry, at
which time you can add simple html tags before and after $input
and use
it as you wish (whether it be emailing it or posting it or what have
you).
Example: (assuming input is already stored in $input)
<html>
<body>
<? echo $input; ?>
</body>
</html>
in practice, you only need the 2 <html></html> tags. This
assumes, of
course, that the information in the $input variable does not have to
be
processed further (such as bolding some letters or changing font
sizes
for some words). If this is the case, have the user input necessary
html
such as <b>words here</b> for bold words, directly into the
textarea
field. hope this helps.
-mark
-----------------------------------------------------
It may also be necessary to remove the backslashes on the $input
variable as well, especially if you have magic_quotes turned on.
The php manual give the stripslashes() function for doing this but
for whatever reason that didn't work for me, I had to use:
preg_replace("/\\\\/si", "", $input);
If anybody can explain that I would appreciate it.
One other thing that I do is:
preg_replace("/\n", "<BR>", $input);
This replaces all newline characters with the html equivelant and
keeps the paragraph formatting that the submitter intended.
-AMPmedia.net
-----------------------------------------------------
I prefer using PHPs built-in function nl2br() as opposed to preg_replace
("/\n", "<BR>", $input);
-BlueDenham