我正在尝试使用数组来确定表中的颜色...但是,我相信我的语法不正确...
数组:
$colors = [
1 => "red",
2 => "yellow",
3 => "green",
];
HTML/PHP:
<td bgcolor=\"$colors[$row['form1']]\">".$row["form1"]."</td>
感谢任何帮助,谢谢!
最佳答案
尝试以下方法
$doc= new DOMDocument(); $doc->loadHTML($html); $colors = array(1 => "red",2 => "yellow",3 => "green");foreach ($doc->getElementsByTagName('td') as $td) {if ($td->getAttribute('bgcolor'),$colors) { /* if true then any color in the array is equal to the td's bgcolor*/ } }
关于php - 如何在 HTML 属性中使用 PHP 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34691794/