Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

newline "\n" not working.

0 views
Skip to first unread message

stevek

unread,
May 13, 2006, 8:17:47 PM5/13/06
to
Following code does not produce any new lines. Any ideas.

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

stevek

unread,
May 13, 2006, 8:18:58 PM5/13/06
to
Sorry ... spell checker corrected some.

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

Alan Little

unread,
May 13, 2006, 8:53:27 PM5/13/06
to
Carved in mystic runes upon the very living rock, the last words of
stevek of comp.lang.php make plain:

> 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.";

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/

rlee0001

unread,
May 13, 2006, 9:58:56 PM5/13/06
to
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

stevek

unread,
May 14, 2006, 1:12:21 AM5/14/06
to
<?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.

stevek

unread,
May 14, 2006, 1:13:51 AM5/14/06
to
Please see prior post.

huckphin

unread,
May 14, 2006, 1:30:13 AM5/14/06
to
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

Jerry Stuckle

unread,
May 14, 2006, 4:17:52 AM5/14/06
to

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.
jstu...@attglobal.net
==================

Alan Little

unread,
May 14, 2006, 6:59:26 AM5/14/06
to
Carved in mystic runes upon the very living rock, the last words of
stevek of comp.lang.php make plain:

> Alan Little wrote:
>> Carved in mystic runes upon the very living rock, the last words of
>> stevek of comp.lang.php make plain:
>>
>>> 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.";
>>
>> 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.
>>

> <?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.

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.

Rik

unread,
May 14, 2006, 8:30:19 AM5/14/06
to

Pure nonsense.

Grtz,
--
Rik Wasmus


Jaspreet

unread,
May 14, 2006, 11:16:30 AM5/14/06
to

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

You could probably do one of the following:

echo "Line 1<br>Line2";

OR

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

Kevin Wells

unread,
May 14, 2006, 2:17:10 PM5/14/06
to
In message <SHu9g.57309$Fs1....@bgtnsc05-news.ops.worldnet.att.net>
stevek <ste...@somewhere.org> wrote:

>Sorry ... spell checker corrected some.
>
>echo "This spans\nmultiple lines. The newlines will be\noutput as well.";
>

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.

Jerry Stuckle

unread,
May 14, 2006, 3:35:15 PM5/14/06
to

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

william...@gmail.com

unread,
May 14, 2006, 6:25:09 PM5/14/06
to
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

huckphin

unread,
May 15, 2006, 10:25:29 PM5/15/06
to
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.

0 new messages