LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 09: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, 09:18 PM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
Code:
echo -en "hello\nworld\n"
 
Old 11-19-2005, 10: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, 04: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, 04:04 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

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


Reply



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-19-2005 11:44 PM
Newline in xmessage? scottjwoodford Linux - General 2 06-09-2005 03:17 PM
newline problem between DOS and Unix format cjs_pro Programming 7 03-11-2005 11:08 AM
Removing newline. Tarts Programming 2 10-16-2003 11:49 AM
What is a newline? raptorsoft2000 Linux - Newbie 6 08-04-2003 10:05 PM

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

All times are GMT -5. The time now is 01:25 AM.

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