Jump to content


Photo

need help with a loop-generated html string/echo


  • Please log in to reply
2 replies to this topic

#1 tefflox

tefflox
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 August 2006 - 12:50 AM

the code is meant to echo a line of 50 characters made of long dashes and nbsp's, but it only echoes a single random number.  How can I get this code to echo the string that I need?

function flow() {
	
        $ar = array( 0 => 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f);
	
	$count = 0;
	$output = "";
	
	while($count < 50) {
		
		$numSpaces = rand(0, 9);
		for($i = 0; $i < $numSpaces, $count < 50; $i++) {
			$output += "&nbsp;";
			$count++;
		}
		
		$r1 = $ar[rand(0, 15)]; $r2 = $ar[rand(0, 15)];
		$g1 = $ar[rand(0, 15)]; $g2 = $ar[rand(0, 15)];
		$b1 = $ar[rand(0, 15)]; $b2 = $ar[rand(0, 15)];		
	
		$col = $r1.$r2.$g1.$g2.$b1.$b2;
		
		//$output += "<span style=\"color:#\".$col."\">&mdash;&mdash;</span>";	
		
		
		$output += "<span style=\"color:#\"";
		$output += $col;
		$output += "\">&mdash;&mdash;</span>";
		
		$count = $count + 2;
		
	}	
	
	echo $output;
	
} // end flow



#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 03 August 2006 - 01:03 AM

In this line:
$ar = array( 0 => 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f);
you need to put the letters in quotes.

You are using += when you should be using .= .  += will add the value of two numbers together...

$a = 1;
$b = 2;
$a += $b;
echo $a; //results in 3;

The .= operator will concatenate two strings.

#3 tefflox

tefflox
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 August 2006 - 01:12 AM

thank you.  it's working fine now.  :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users