Jump to content

Archived

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

tefflox

need help with a loop-generated html string/echo

Recommended Posts

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?

[code]
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

[/code]

Share this post


Link to post
Share on other sites
In this line:
[code]$ar = array( 0 => 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f);[/code]
you need to put the letters in quotes.

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

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

The .= operator will concatenate two strings.

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.