It is not PHP but HTML. In HTML any 'whitespace character', that is space,
tab or new line, is taken as a single whitespace character. It has nothing
to do with PHP.
You can either replace them with which prints as a space but doesn't
fall into the category of 'whitespace character' and is thus respected or
you can use the <pre> tag, which will produce a mono-spaced output with all
blanks and new lines as they come.
Satyam
----- Original Message -----
From: "Geoffrey E. Quelch" <gequelch@xxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Friday, April 14, 2006 9:15 PM
Subject: Compacting multiple spaces...
Hi,
I am running a self-compiled PHP version 4.4.2 on Apache 1.3.34 on White
Box
Enterprise Linux 3.
I found a problem in my database access code (Oracle 9.2.0.4 if it
matters)
and have determined that spaces in string variables are being compacted on
output in PHP.
This PHP extract, when run, illustrates the problem:
<?php
$name = "Space 9";
print "<p>Length: ".strlen($name);
printf("<p>Variable: %s",$name);
print "<p>Variable: '".$name."'";
echo "<p>Variable: ".$name;
for($i=0; $i< strlen($name); $i++)
print "<p>Character: ".$i."\"$name[$i]\"";
?>
even though the string does contain 9 consecutive spaces, only one is ever
printed to the screen with echo, print or printf. There is nothing in the
documentation for these functions that I've found that says this is the
expected behavior, or how to override if one really wants those spaces
honored.
Why is this important? Well, the application this is in allows users to
define
text strings that are inserted into the database with multiple consecutive
spaces, however, when constructing select lists in PHP using these same
entries the spaces are compacted, so the SELECT now doesn't match what is
in
the database.
Is there a way to override this behavior?
Thanks,
Geoff Quelch
--
Geoff Quelch
Email: gequelch@xxxxxxxx
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php