Re: [PHP] newline problem

2002-07-24 Thread Jason Wong

On Thursday 25 July 2002 12:11, Wormy . wrote:
 Dear all,
  this sounds like a silly problem but i really dunno how to fix it!

  In the php manual on php.net said we can use an embedded newline just
 by writing the string on different line by pressing enter key. This
 doesn't work for me. Another thing is \n also work. For example:

 ?php
   echo ' You can also have embedded newlines in strings,
   like this way.';
   echo 'I am trying to include at this point: \n a newline';
 ?

 the output i get is:
 You can also have embedded newlines in strings, like this way.I am trying
 to include at this point: \n a newline

 Am I doing anything wrong? Thanks!

Stuff like \n are only interpreted if they are enclosed in double-quotes:

This works\n
'This does not work\n'

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Iron Law of Distribution:
Them that has, gets.
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] newline problem

2002-07-24 Thread Justin French

A new line is NOT a br or br / in HTML.

Assuming this output is for HTML (browser) purposes, the browser will ignore
newlines.

?php
echo 'this is first linebrsecond linebrthird line'; // works for HTML
?
Will print...

this is first line
second line
third line

... to the browser.



If you have a $string with \n's in it, you can convert these to br /'s
with the function nl2br():

?
// with newlines typed in, will work in email and text files:
$string = 'this is first line\nsecond line\nthird line';

// convert \n's to br's for HTML output
$string_html = nl2br($string);


// newlines done with hitting return will work in email and txt files
$string = 'this is first line
second line
third line';

// convert \n's to br's for HTML output
$string_html = nl2br($string);

?


Think about it -- this HTML...

P
something
something
something
/P

... will output somethingsomethingsomething to the browser, because browsers
ignore newlines, tabs, and other whitespace in text.  On the other hand,
this HTML...

P
somethingbr
somethingbr
something
/P

... would achieve three separate lines, so you need to do the same thing
when echoing.


HTH

Justin French


on 25/07/02 2:11 PM, Wormy . ([EMAIL PROTECTED]) wrote:

 Dear all,
 this sounds like a silly problem but i really dunno how to fix it!
 
 In the php manual on php.net said we can use an embedded newline just
 by writing the string on different line by pressing enter key. This
 doesn't work for me. Another thing is \n also work. For example:
 
 ?php
 echo ' You can also have embedded newlines in strings,
 like this way.';
 echo 'I am trying to include at this point: \n a newline';
 ?
 
 the output i get is:
 You can also have embedded newlines in strings, like this way.I am trying
 to include at this point: \n a newline
 
 Am I doing anything wrong? Thanks!
 
 Ser Yee
 
 _
 Join the world’s largest e-mail service with MSN Hotmail.
 http://www.hotmail.com
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php