Page 1 of 1

Not able to use <br> or \n

Posted: Mon Aug 05, 2002 4:42 pm
by famouskey
:? I can't do the following:

echo "$_POST['Choice']\n";

nor

echo "$_POST['Choice']<br>";


???? Is it not allowed in PHP 4.2.1?

couldn't do this either..

echo "$Choice<br>";

Posted: Mon Aug 05, 2002 4:46 pm
by hob_goblin
echo $_POST['Choice']."\n";

try that..

Posted: Mon Aug 05, 2002 4:50 pm
by famouskey
can't do that either:

echo $_POST['Choice']."\n";

whether the full stop is intended there or not..

Posted: Mon Aug 05, 2002 5:48 pm
by famouskey
Got it! Hate 4.2 for changing defining variables..

The below would show a space instead of line break:

echo $_POST['Choice'], "\n";

To achieve line break need html <br>:

echo $_POST['Choice'], "<br>";


Also found comma and full stop have same use here.

Posted: Mon Aug 05, 2002 5:58 pm
by protokol
Another way to achieve the same thing is this:

echo "{$_POST['Choice']}<br>";

Notice the { and }

Posted: Mon Aug 05, 2002 6:01 pm
by protokol
One more thing I wanted to point out. Whenever you already have an HTML document defined, (<html></html> tags are present), the \n will not print a line break. You would need to use <br> instead because a line break in an HTML document is <br>.

BUT, if you are only printing text and you need a line break, both \n and <br> will work. So remember, <br> when HTML page, \n when plain text.

Posted: Mon Aug 05, 2002 6:04 pm
by famouskey
Don't you think that's kind of wordy for 4.2+ when every time you need to type $_REQUEST[] for a variable?

.... 8O

Posted: Mon Aug 05, 2002 6:06 pm
by famouskey
:D Thanks protokol to point out usage of \n & <br>..

Posted: Mon Aug 05, 2002 9:17 pm
by EricS
If I'm not mistaken when using echo and print: If you use double quotes it will not extrapolate variables to values. So you can't put $_POST or any other variable inside double quotes if you really want the value of the variable.

Also when trying to get the value from an array (which is what $_POST is) then you must incorporate it in braces {}.

Posted: Mon Aug 05, 2002 9:50 pm
by llimllib
you can turn register_globals on if you don't want to do $_REQUEST. However, there is a slight security issue there because then information submitted via any request is used in your script, not just the info from the particular request you want.

Posted: Mon Aug 05, 2002 10:37 pm
by jason
famouskey wrote:Got it! Hate 4.2 for changing defining variables..

The below would show a space instead of line break:

echo $_POST['Choice'], "\n";

To achieve line break need html <br>:

echo $_POST['Choice'], "<br>";


Also found comma and full stop have same use here.
Okay, two things. First, \n and the BReak tag are two completely different things. PHP 4.2 has nothing to do with this. \n Doesn't put a space, it puts a line break in.

Also, using a comma in echo instead of the concatenation symbol (.) is slight faster, because PHP doesn't have to do that concatenation.

Posted: Mon Aug 05, 2002 10:50 pm
by protokol
Way off topic, but I am DYING to know. Who is the girl in the picture?

Posted: Tue Aug 06, 2002 9:49 am
by hob_goblin
it's random... will be a different girl each time

Posted: Tue Aug 06, 2002 3:51 pm
by learning_php_mysql
protokol wrote:One more thing I wanted to point out. Whenever you already have an HTML document defined, (<html></html> tags are present), the \n will not print a line break. You would need to use <br> instead because a line break in an HTML document is <br>.

BUT, if you are only printing text and you need a line break, both \n and <br> will work. So remember, <br> when HTML page, \n when plain text.
well to make the outputted html look pretty when somebody looks at your "source" this works for me...

Code: Select all

echo("<table>\n\t<tr>\n\t\t<td>stuff</td>\n\t\t</tr>\n\t</table>");


.... im not really shure this is wat you're talking about or not