Jump to content


Photo

spacing problems


  • Please log in to reply
5 replies to this topic

#1 nick5449

nick5449
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 05 July 2006 - 08:55 PM

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

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.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 05 July 2006 - 08:56 PM

Web browsers do not display "\n" as a line break, you need to output the
<br>
tag for that.

Ken

#3 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 05 July 2006 - 08:58 PM

A suggestion for you nick, you can make your script shorter using "foreach":

<?php
foreach($test as $value){
echo($val."<br>");
}
?>
 

Orio.
Think you're smarty?

(Gone until 20 to November)

#4 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 05 July 2006 - 09:00 PM

<br /> for break but you could do it like

<?php

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

// or

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


#5 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 05 July 2006 - 09:04 PM

you can use implode() to do this
echo implode("<br />", $test);

NoGray.com


#6 nick5449

nick5449
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 05 July 2006 - 09:05 PM

Awesome, that helps a lot.  Thanks for the suggestions.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users