LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-19-2005, 10:15 PM   #1
harrylmh
LQ Newbie
 
Registered: Nov 2005
Location: Australia
Posts: 18

Rep: Reputation: 0
Question newline problem


How do I print:
PHP Code:
hello
world 
with echo?

The following doesn't work like the one above:
echo hello\nworld
echo hello\0nworld
echo "hello\nworld"
The \n doesn't get interpreted as a newline, but why?

What's the right command?

regards
 
Old 11-19-2005, 10:18 PM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
Code:
echo -en "hello\nworld\n"
 
Old 11-19-2005, 11:09 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
randyding -

harrylmh's suggestion about "echo -en" is exactly correct ... if your question is about the shell's "echo".

I'm wondering if maybe your question is actually about php's "echo" - perhaps you want to see newlines in an HTML web page generated by PHP.

If you're not seeing the newline in a web browser, then the solution is to add an HTML "<br>" tag

EXAMPLE:
<?php
echo "Hello<br>world\n";
?>

'Hope that helps .. PSM

PS:
If you were asking about the shell echo in the first place, harrylmh's answer should already have you squared away. In that case, please accept my humble apologies ;-)
 
Old 11-20-2005, 05:54 AM   #4
harrylmh
LQ Newbie
 
Registered: Nov 2005
Location: Australia
Posts: 18

Original Poster
Rep: Reputation: 0
Yes! thanks, randyding, your code worked.
PS: yes, I was referring to shell
 
Old 11-21-2005, 05:04 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516

Rep: Reputation: 239Reputation: 239Reputation: 239
-ethat's an annoying bash thing.
echo '\n' works in ksh and sh
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
php + newline??? blizunt7 Programming 1 06-20-2005 12:44 AM
Newline in xmessage? scottjwoodford Linux - General 2 06-09-2005 04:17 PM
newline problem between DOS and Unix format cjs_pro Programming 7 03-11-2005 12:08 PM
Removing newline. Tarts Programming 2 10-16-2003 12:49 PM
What is a newline? raptorsoft2000 Linux - Newbie 6 08-04-2003 11:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration