Escape characters in Text field

A

Anonymous

Guest
Hi!

This is probably a pretty simple one but I can't figure it out.

How do I pass on linebreaks and other escape sequences from a textfield to another page? Do I need to specify something for the textfield itself or is it the variable handling on the next page?

Thank you in advance!
 
Try looking at http://www.php.net/nl2br - not sure if it's quite what you want, but it might be a good start.

Andrew
 
I'm not sure if i get it right, anyway here is an answer for what i've undertand.

If you want to use a the content that cames from a form field, like it is, keeping linebreaks such as white spaces, you can do:

If that content could be an eventually output to an html page, usually we use php's nl2br() function to keep the content's linebreaks.
This function will tranform every linebreak (\n) into an html br tag (<br />).

Example:
Code:
$new_content = nl2br($content_from_field);
So this '$new_content' will be exactly the same way (linebreaks) as the one filled in the form, if you print it inside an html code.

I usually don't use more than this one, but sometimes is necesary to replace some other stuff.

You can use php's str_replace() function for this same purpose and/or to replace other scape sequences.
Example:
Code:
$content = str_replace("\n", "<br />", $content);

$content = str_replace("  ", " ", $content);

$content = str_replace('<', '<', $content);

See more in the above links ;)
Cheers
 
hey, I got there first... :p

Heh - only 2 minutes in it, but I guess that means we understood the problem in the same way, so hopefully we both got it right :)

Andrew
 
Heh heh :D

I actually saw your post when made my last preview and as i saw i'd got it right like you... i decide to post it as same!

Cheers
Gesf
 
Both of you got it right, sorry for being unclear :???:

Your answers solved the problem! Thanks!
 
Back
Top