Page 1 of 1

newbie - nl2br

Posted: Sun Feb 02, 2003 5:39 am
by kammy
I'm stuck on the The PHP Beginners Tutorial

How do I make this for post PHP 4.2

The tut shows this;

$MyTextarea = nl2br($MyTextarea);
echo($MyTextarea);

I've tried variations of this;

$MyTextarea = nl2br ($_POST['MyTextarea']);
echo $_POST['MyTextarea'];

So far I can't make it work...

Tnx.i.a.
kammy...

Posted: Sun Feb 02, 2003 5:43 pm
by McGruff
Are you sure that you named a form field "MyTextarea" (and entered some text before running the form processor script - duh :lol: )?

Also, would the form send the form field name as lower case (I don't know)? If it does, $_POST['mytextarea'] ought to work.

Posted: Mon Feb 03, 2003 2:37 am
by twigletmac
To check what is in the $_POST array you can do:

Code: Select all

echo '<pre>';
print_r($_POST);
echo '</pre>';
at the top of the script that handles the form processing.

One thing I did notice was you have this:

Code: Select all

$MyTextarea = nl2br($_POST['MyTextarea']);
and then this:

Code: Select all

echo $_POST['MyTextarea'];
which means that you are echoing out the original variable that has not had the nl2br() function run on it. To view the text with the HTML line breaks added in you would need to do:

Code: Select all

$MyTextarea = nl2br($_POST['MyTextarea']); 
echo $MyTextarea;
or if you're not going to use $MyTextarea anywhere else, why even bother making a temporary variable - just do:

Code: Select all

echo nl2br($_POST['MyTextarea']);

Mac

Thanks

Posted: Mon Feb 03, 2003 3:10 am
by kammy
Great explanation.

Of course both of your options work.

It's all a bit overwhelming when you've never done any coding before.

That PHP Beginners Tutorial is by far the best I've come across so far.

kammy...

:arrow: Beginners Tutorial;
http://www.phpcomplete.com/tutorials.ph ... adTutorial
:arrow: Read in conjunction with - Working with Form Variables in PHP 4.2+;
http://www.phpcomplete.com/tutorials.ph ... adTutorial