reg ex inside of nested for loops, inside of a function
Posted: Mon Feb 11, 2008 9:39 am
I have this function, take(), which prints a table on the screen.
I call the function like this:
take('#ffffff','green','red','blue','gray','black','#cc00ff','6x6', '#669900');
I want to put patterns to search for hexadecimals
preg_match("/#[0-9ABCDEF]{6}/i",$values)
and for dimensions
preg_match("/[0-9]+x[0-9]+/i",$values)
when the function is called.
My question is how ca I put those pattern, thus in final to have on the screen the table with each color founded in each cell and the number of cell to be by the dimension found (6x6)-a square with 6 cells on horizontal and 6 cells on vertical ?
function take()
{
$funcArgs = func_get_args(); // return an array with the elemets passed to the function
echo '<table border="2px solid black">';
for($row=0; $row < 4; $row++) // outer loop
{
echo '<tr>';
for($col=0; $col < 4; $col++) //inner loop
{
echo '<td>'.$row.$col.'</td>';
}
echo '</tr>';
}
echo '</table>';
}
I call the function like this:
take('#ffffff','green','red','blue','gray','black','#cc00ff','6x6', '#669900');
I want to put patterns to search for hexadecimals
preg_match("/#[0-9ABCDEF]{6}/i",$values)
and for dimensions
preg_match("/[0-9]+x[0-9]+/i",$values)
when the function is called.
My question is how ca I put those pattern, thus in final to have on the screen the table with each color founded in each cell and the number of cell to be by the dimension found (6x6)-a square with 6 cells on horizontal and 6 cells on vertical ?
function take()
{
$funcArgs = func_get_args(); // return an array with the elemets passed to the function
echo '<table border="2px solid black">';
for($row=0; $row < 4; $row++) // outer loop
{
echo '<tr>';
for($col=0; $col < 4; $col++) //inner loop
{
echo '<td>'.$row.$col.'</td>';
}
echo '</tr>';
}
echo '</table>';
}
