Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old May 14th, 2006, 01:25 AM
stevek
Guest
 
Posts: n/a
Default newline "\n" not working.

Following code does not produce any new lines. Any ideas.

echo "This spans\multiple lines. The newlines will be\noutput as well.";
  #2  
Old May 14th, 2006, 01:25 AM
stevek
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

Sorry ... spell checker corrected some.

echo "This spans\nmultiple lines. The newlines will be\noutput as well.";

stevek wrote:[color=blue]
> Following code does not produce any new lines. Any ideas.
>
> echo "This spans\multiple lines. The newlines will be\noutput as well.";[/color]
  #3  
Old May 14th, 2006, 01:55 AM
Alan Little
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

Carved in mystic runes upon the very living rock, the last words of
stevek of comp.lang.php make plain:
[color=blue]
> stevek wrote:[color=green]
>> Following code does not produce any new lines. Any ideas.
>>
>> echo "This spans\multiple lines. The newlines will be\noutput as
>> well.";[/color]
>
> Sorry ... spell checker corrected some.
>
> echo "This spans\nmultiple lines. The newlines will be\noutput as
> well.";[/color]

So, you're saying that this will output the literal string:

This spans\nmultiple lines. The newlines will be\noutput as well.

Is the bit you posted above a direct cut-and-paste from your script? If
not, check that you are in fact using double quotes and not single.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
  #4  
Old May 14th, 2006, 03:05 AM
rlee0001
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

HTML ignores excess whitespace including newlines. Are you viewing the
page in the browser or viewing the source for the page? If you are
viewing the output in the browser window itself, is the text contained
in a PRE tag?

-Robert

  #5  
Old May 14th, 2006, 06:15 AM
stevek
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

<?php

$conn = @mysql_connect( "campania", "sfk", "" )
or die( "Sorry - could not connect to MySQL" );
echo "$conn\n";
//$rs1 = @mysql_create_db( $_REQUEST['db'] );
echo "This spans\nmultiple lines. The newlines will be\noutput as well.";
?>

produces......

Resource id #2 This spans multiple lines. The newlines will be output as
well.


Alan Little wrote:[color=blue]
> Carved in mystic runes upon the very living rock, the last words of
> stevek of comp.lang.php make plain:
>[color=green]
>> stevek wrote:[color=darkred]
>>> Following code does not produce any new lines. Any ideas.
>>>
>>> echo "This spans\multiple lines. The newlines will be\noutput as
>>> well.";[/color]
>> Sorry ... spell checker corrected some.
>>
>> echo "This spans\nmultiple lines. The newlines will be\noutput as
>> well.";[/color]
>
> So, you're saying that this will output the literal string:
>
> This spans\nmultiple lines. The newlines will be\noutput as well.
>
> Is the bit you posted above a direct cut-and-paste from your script? If
> not, check that you are in fact using double quotes and not single.
>[/color]
  #6  
Old May 14th, 2006, 06:15 AM
stevek
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

Please see prior post.

rlee0001 wrote:[color=blue]
> HTML ignores excess whitespace including newlines. Are you viewing the
> page in the browser or viewing the source for the page? If you are
> viewing the output in the browser window itself, is the text contained
> in a PRE tag?
>
> -Robert
>[/color]
  #7  
Old May 14th, 2006, 06:35 AM
huckphin
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

All you need to do is statement separator (the period (.)). Then put
your code in two statements such as this.

Line #5 is [echo "$conn\n";]
Line #5 needs to be corrected to [echo $conn."\n";]

LIne #7 is [echo "This spans\nmultiple lines. The newlines will
be\noutput as well."; ]
Line #7 needs to be
[echo "This spans"."\n"."multiple lines. The newlines will
be"."\n"."output as wee.";]

-Huck Finn

  #8  
Old May 14th, 2006, 09:25 AM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

stevek wrote:[color=blue]
> Please see prior post.
>
> rlee0001 wrote:
>[color=green]
>> HTML ignores excess whitespace including newlines. Are you viewing the
>> page in the browser or viewing the source for the page? If you are
>> viewing the output in the browser window itself, is the text contained
>> in a PRE tag?
>>
>> -Robert
>>[/color][/color]

Steve,

No, you see Robert's post. He is correct. Check the page source.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  #9  
Old May 14th, 2006, 12:05 PM
Alan Little
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

Carved in mystic runes upon the very living rock, the last words of
stevek of comp.lang.php make plain:
[color=blue]
> Alan Little wrote:[color=green]
>> Carved in mystic runes upon the very living rock, the last words of
>> stevek of comp.lang.php make plain:
>>[color=darkred]
>>> stevek wrote:
>>>> Following code does not produce any new lines. Any ideas.
>>>>
>>>> echo "This spans\multiple lines. The newlines will be\noutput as
>>>> well.";
>>> Sorry ... spell checker corrected some.
>>>
>>> echo "This spans\nmultiple lines. The newlines will be\noutput as
>>> well.";[/color]
>>
>> So, you're saying that this will output the literal string:
>>
>> This spans\nmultiple lines. The newlines will be\noutput as well.
>>
>> Is the bit you posted above a direct cut-and-paste from your script?
>> If not, check that you are in fact using double quotes and not
>> single.
>>[/color]
> <?php
>
> $conn = @mysql_connect( "campania", "sfk", "" )
> or die( "Sorry - could not connect to MySQL" );
> echo "$conn\n";
> //$rs1 = @mysql_create_db( $_REQUEST['db'] );
> echo "This spans\nmultiple lines. The newlines will be\noutput as
> well."; ?>
>
> produces......
>
> Resource id #2 This spans multiple lines. The newlines will be output
> as well.[/color]

If you mean it outputs this in your browser (I don't see a shebang line,
so I assume you're not running this on the command line), then Robert
gave you the answer. A newline is equivalent to a space, in HTML.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
  #10  
Old May 14th, 2006, 01:35 PM
Rik
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

huckphin wrote:[color=blue]
> All you need to do is statement separator (the period (.)). Then put
> your code in two statements such as this.
>
> Line #5 is [echo "$conn\n";]
> Line #5 needs to be corrected to [echo $conn."\n";]
>
> LIne #7 is [echo "This spans\nmultiple lines. The newlines will
> be\noutput as well."; ]
> Line #7 needs to be
> [echo "This spans"."\n"."multiple lines. The newlines will
> be"."\n"."output as wee.";][/color]

Pure nonsense.

Grtz,
--
Rik Wasmus


  #11  
Old May 14th, 2006, 04:25 PM
Jaspreet
Guest
 
Posts: n/a
Default Re: newline "\n" not working.


stevek wrote:[color=blue]
> Following code does not produce any new lines. Any ideas.
>
> echo "This spans\multiple lines. The newlines will be\noutput as well.";[/color]

You could probably do one of the following:

echo "Line 1<br>Line2";

OR

echo "<pre>Line 1\nLine2</pre>";

  #12  
Old May 14th, 2006, 07:45 PM
Kevin Wells
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

In message <SHu9g.57309$Fs1.43996@bgtnsc05-news.ops.worldnet.att.net>
stevek <stevek@somewhere.org> wrote:
[color=blue]
>Sorry ... spell checker corrected some.
>
>echo "This spans\nmultiple lines. The newlines will be\noutput as well.";
>[/color]

Change \n to <br>

--
Kev Wells http://kevsoft.topcities.com
http://kevsoft.co.uk/
ICQ 238580561
IF your nose runs and your feet smell it means your upside down.
  #13  
Old May 14th, 2006, 08:35 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

huckphin wrote:[color=blue]
> All you need to do is statement separator (the period (.)). Then put
> your code in two statements such as this.
>
> Line #5 is [echo "$conn\n";]
> Line #5 needs to be corrected to [echo $conn."\n";]
>
> LIne #7 is [echo "This spans\nmultiple lines. The newlines will
> be\noutput as well."; ]
> Line #7 needs to be
> [echo "This spans"."\n"."multiple lines. The newlines will
> be"."\n"."output as wee.";]
>
> -Huck Finn
>[/color]

Sorry, Huck. It will all come out in one line. Try it yourself in an HTML page.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  #14  
Old May 14th, 2006, 11:25 PM
william.clarke@gmail.com
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

stevek pass it through nl2br...

<?php
echo nl2br("This spans\multiple lines. The newlines will be\noutput as
well.");
?>

http://au.php.net/manual/en/function.nl2br.php

  #15  
Old May 16th, 2006, 03:25 AM
huckphin
Guest
 
Posts: n/a
Default Re: newline "\n" not working.

Yea, so my previous post was wrong. For some reason I was thinking
that stevek was referring to the output inside the source code to make
go to a new line. My mistake. Thank you for the correction, though.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.