Click to See Complete Forum and Search --> : php problem


Caesar War
01-04-2003, 01:57 PM
I decided to finally learn php and so I installed both apache and php on my laptop computer (laptop runs under XP) and run it as a server so i could go and do stuff.

I was going through the ol hello world stuff and everything was going fine until i got to the special characters part

if I go and do this

<?php
echo "Hi my name is \nCaesar";
?>

it is supposed to output this:
Hi my name is
Caesar

right ??

but it's not doing it ! what is actually shows is:
Hi my name is Caesar <-- without the newline

however when i view the source on explorer it does shows like it is supposed to (with the newline thing)

same thing happens with \r and \t

doesnt happen with the other special chars... if I go and do this
echo "Hi my name is \$Caesar";
it does indeed shows
Hi my name is $Caesar

so... can somebody help me ? :confused:

Grizzly
01-04-2003, 04:32 PM
PHP did it's job by printing the new line character, you're just no understanding the nature of HTML.

HTML has a "<br>" tag for line breaks. New line characters in the source code mean absolutely nothing to the HTML parser. You have to remember that all whitespace characters are ignored by the HTML parser. (new lines are considered whitespace)

However, if you want new line characters to actually display line breaks on your web page, simply wrap your content in the "<pre></pre>" tag.

Caesar War
01-04-2003, 04:52 PM
I tought the PHP did the parsing part

but I guess that makes more sense

thank you :)

Grizzly
01-04-2003, 05:17 PM
PHP parses PHP code on the server-side, and the web browser parses the resulting HTML on the client-side. Make sense?

Caesar War
01-04-2003, 10:41 PM
yup... thanks :)