【发布时间】:2011-08-25 20:26:29
【问题描述】:
我有代码将随机字体应用于从 .txt 文件的最后 20 行获取的文本 div。我想对每一行应用一个不同的随机字体...任何指针?
<?php
$fonts = array("Helvetica", "Arial", "Courier", "Georgia", "Serif", "Comic Sans", "Tahoma");
shuffle($fonts);
$randomFont = array_shift($fonts);
$output = "";
$lines = array_slice(file("users.txt"), -20, 20);
foreach ( $lines as $line )
{
$output .= '<div style="font-family:' . $randomFont . '; margin-left: ' . rand(0, 60) . '%; opacity: 0.8;">' . $line . '</div>';
}
echo $output;
?>
【问题讨论】: