473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

newline \n and tab \t Not Working in PHP 5.0.3 | Apache 2.0.52 | Windows XP Pro

The following examples (see PHP 5 for Dummies, p. 82)
do not produce the expected results:

$string = "Hello \nWorld";
echo $string;

and

$string = "Line 1 \n\tLine 2";
echo $string;

The first instance is for a line break such that the words are stacked:

Hello
World

The second instance is for a line break with a tabbed second line:

Line 1
Line 2

Do I need to change or add something in one of the configuration files?
Otherwise, is there a known fix for this? Thank you for any assistance.

Jul 17 '05 #1
7 15255
ga*****@cwnet.com wrote:
The following examples (see PHP 5 for Dummies, p. 82)
do not produce the expected results:

$string = "Hello \nWorld";
echo $string;

and

$string = "Line 1 \n\tLine 2";
echo $string;

The first instance is for a line break such that the words are
stacked:

Hello
World

The second instance is for a line break with a tabbed second line:

Line 1
Line 2

Do I need to change or add something in one of the configuration
files?
Otherwise, is there a known fix for this? Thank you for any
assistance.


Newlines and tabs are ignored by browsers when rendering HTML. If you
view the source of the page in your browser you will see the tabs and
newline breaks are there.

To do a line break in HTML you need to use the <br /> tag, or enclose
your sentance in <p> and </p> tags.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2
I noticed that Message-ID:
<11*********************@l41g2000cwc.googlegroups. com> from
ga*****@cwnet.com contained the following:
The following examples (see PHP 5 for Dummies, p. 82)
do not produce the expected results


I'd be interested to see what the book actually says the code does...

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
The book says the code should produce the two results shown in my
original post (which are copied there from the book). These expected
results appear below the examples in my post, a little farther down in
its text, as "first instance" and "second instance"--i.e., the first
result is to provide a line break (newline \n), and the second result
is to provide both a line break and a tab (newline tab n\t\).

Jul 17 '05 #4
ga*****@cwnet.com wrote:
The book says the code should produce the two results shown in my
original post (which are copied there from the book). These expected
results appear below the examples in my post, a little farther down in
its text, as "first instance" and "second instance"--i.e., the first
result is to provide a line break (newline \n), and the second result
is to provide both a line break and a tab (newline tab n\t\).


It should provide the expected results when you use View Source to see
the raw HTML code. However, when the browser displays the page it will
ignore the extra whitespace (spaces, tabs, and newlines are all whitespace).
Jul 17 '05 #5
Thank you.

It seems that the usefulness of the \n and \t features is limited to
formatting source code for easy readability.

It looks like <p></p> tags would be the best choice for onscreen
formatting. I imagine using CSS classes in them would permit such
things as the equivalent of tabbing, in addition to the default line
breaks.

Jul 17 '05 #6
ga*****@cwnet.com wrote:
The following examples (see PHP 5 for Dummies, p. 82)
do not produce the expected results:

$string = "Hello \nWorld";
echo $string;

and

$string = "Line 1 \n\tLine 2";
echo $string;

The first instance is for a line break such that the words are stacked:

Hello
World

The second instance is for a line break with a tabbed second line:

Line 1
Line 2

Do I need to change or add something in one of the configuration files?
Otherwise, is there a known fix for this? Thank you for any assistance.


Since browsers collapse all consecutive whitespace to a single space by
default, you could do this:

echo '<pre>';
echo $string;
echo '</pre>';

HTH,
JP

--
Sorry, <de*****@cauce.org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
Jul 17 '05 #7
*** ga*****@cwnet.com escribió/wrote (13 Feb 2005 19:35:33 -0800):
Do I need to change or add something in one of the configuration files?


If you are expecting plain text output, add this to the very beginning of
the file:

header('Content-Type: text/plain');
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Manda tus dudas al grupo, no a mi buzón
-+ Send your questions to the group, not to my mailbox
--
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Nuno Paquete | last post by:
Hi group. How can I get PHP working under windows, with Apache web server? Where can I find the module? I suppose that I need to install a module like in Linux... Thanks in advance. Nuno...
10
by: sp | last post by:
The application is written in Visual Basic / .NET and working without problems under Windows XP, Windows 2000, Windows 2003 but it isn't working under Windows ME and Windows 98 - the computer...
4
by: arorap | last post by:
I've mod_php installed with Apache 2.2. In one of my folders, I'm using the cgihandler as the PythonHandler as my target host runs python only as CGI. Here cgi.FieldStorage() doesn't seem to work....
4
by: tekeste | last post by:
Hello guys. is there someone out there to tell me why TAB key is not working in windows CE mobile application in .net? I just want to move from one textbox to the next using TAB key, but it won't...
2
by: abhilash12 | last post by:
hai ajax is not working in windows nt machine in nt machine status=501 so pls help me
1
by: Gowri | last post by:
Hello, I am new to Python and am trying to setup Apache to serve Python using mod_python. I'm using a Windows XP box. here is a list of steps i followed for the installation: 1. Installed...
4
by: adnanjunk | last post by:
Hi, Having a little issue with .htaccess not working on windows server. I have clean url's setup using the htaccess file, working fine on linux server. I have researched for a while and found...
6
by: josequinonesii | last post by:
I've searched, I've read, I've tested and re-read numerous post but to no avail yet... Quite simply, the settings I've applied to my httpd.conf, httpd-vhost.conf and my hosts files simply does not...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.