Jump to content

Archived

This topic is now archived and is closed to further replies.

nick5449

spacing problems

Recommended Posts

I have an array that I want to display, but with a enter in between them.  The code I have is this: [code] $x = 0;
while($x != count($test)){
echo $test[$x];
echo "\n";
$x++;
}[/code]

The array is displayed but the enter isn't.  Why wont '\n' work and how else can I get an enter to be displayed? Thanks.

Share this post


Link to post
Share on other sites
Web browsers do not display "\n" as a line break, you need to output the [code]<br>[/code] tag for that.

Ken

Share this post


Link to post
Share on other sites
A suggestion for you nick, you can make your script shorter using "foreach":

[code]<?php
foreach($test as $value){
echo($val."<br>");
}
?>[/code]
[hr]

Orio.

Share this post


Link to post
Share on other sites
<br /> for break but you could do it like

[code]
<?php

while($x != count($test)) {
  echo $test[$x] ." <br /><br />";
  $x++;
}

// or

while ($x != count($test)) {
  echo "<p>{$test[$x]}</p>";
}
?>
[/code]

Share this post


Link to post
Share on other sites
you can use [url=http://us2.php.net/manual/en/function.implode.php]implode()[/url] to do this
[code]
echo implode("<br />", $test);
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.