At 12:15 PM 4/14/2006, Geoffrey E. Quelch wrote:
even though the string does contain 9 consecutive spaces, only one is ever printed to the screen with echo, print or printf.
At 01:19 PM 4/14/2006, Satyam wrote:
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.
Geoffrey, another way of saying this is that it's only the SCREEN RENDERING that makes multiple whitespace characters APPEAR to be a single space. If you view the source of your page I think you'll see all your spaces intact.
Since the multiple spaces are really there in your string, you should be able to operate on all of them, for example using string-array functions.
In your script:
$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]\"";
...the lines I've marked with an asterisk should reveal the true length of the string, including all nine spaces, even though the screen-print functions make it look like they've been consolidated into one space.
Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php