Not able to use <br> or \n

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
famouskey
Forum Newbie
Posts: 6
Joined: Mon Aug 05, 2002 4:42 pm

Not able to use <br> or \n

Post 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>";
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

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

try that..
famouskey
Forum Newbie
Posts: 6
Joined: Mon Aug 05, 2002 4:42 pm

Post by famouskey »

can't do that either:

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

whether the full stop is intended there or not..
famouskey
Forum Newbie
Posts: 6
Joined: Mon Aug 05, 2002 4:42 pm

Post 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.
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Another way to achieve the same thing is this:

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

Notice the { and }
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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.
famouskey
Forum Newbie
Posts: 6
Joined: Mon Aug 05, 2002 4:42 pm

Post 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
famouskey
Forum Newbie
Posts: 6
Joined: Mon Aug 05, 2002 4:42 pm

Post by famouskey »

:D Thanks protokol to point out usage of \n & <br>..
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post 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 {}.
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post 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.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post 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.
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Way off topic, but I am DYING to know. Who is the girl in the picture?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

it's random... will be a different girl each time
learning_php_mysql
Forum Commoner
Posts: 27
Joined: Sun Aug 04, 2002 12:58 pm
Location: WA

Post 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
Post Reply