I am trying to generate a random bit of html via php, I can’t get it to work?
$i = 96;
$minder = '';
while($i >= 0) {
// 1
if (rand(0, 1) == 0) {
$minder . '<li class="0 1" title="1"></li>';
// 2
} else {
$minder . '<li class="0 2" title="2"></li>';
}
--$i;
}
echo $minder;
How do I get the li to append to the string minder? I should end up with a list of 96 li?
Syntax should be:
Note the
.=Concatenating two strings is done with a
.(i.e.$string = "first part"." second part";) but if you want to concatenate a string to an existing variable, you can do it the long way:or use the shorthand syntax, which is much simple:
Also… your class names!
Using a numeric digit as a class name is going to give you headaches down the road. Technically you can do it, but it requires vigilance and you may just want to avoid it by calling your class ‘class_1’ and ‘class_2’, etc. From w3c:
Given how easy it is to just avoid this, I’d follow Triptych’s rule on this: