<?php
$tr_no = mysql_num_rows($query);
$ii = 0; //iterator;
while($news = mysql_fetch_array($query))
//replacing special characters
$replacename = eregi_replace(" ", "-", $news['3']);
$pattern = array();
$pattern[0] = '-';
$pattern[1] = "'";
$replace = array();
$replace[0] = '-';
$replace[1] = ''';
$news['2'] = preg_replace($pattern,$replace,$news['2']);
$news['1'] = preg_replace($pattern,$replace,$news['1']);
echo "<div style='width: 600px;' align='center'>";
if($ii % 2 == 0){
echo "<div style='width: 290px; height: 350px; float: left; padding:5px;'><h3 style='color:#ff0000; font-size: 14px;'>".$news['2']."</h3><p style='font-size:12px;'>".$news['1']."...</p><p><a href=\"".$href ."/". $replacename ."/item/".$news['0']."\">read more...</a></p></div>";
}
if($ii % 2 == 1){
echo "<div style='width: 290px; height: 350px; float: left; padding:5px;'><h3 style='color:#ff0000; font-size: 14px;'>".$news['2']."</h3><p style='font-size:12px;'>".$news['1']."...</p><p><a href=\"".$href ."/". $replacename ."/item/".$news['0']."\">read more...</a></p></div>";
}
echo "</div>";
$ii++;
}
?>
代码在循环时从数据库中输出字符串,但是在html格式中有些字符出现无效,详见:http: //ipaidabribenaija.com/newsletter2.php
我也用过str_replace()
代替preg_replace()
,但是函数在这个中无效情况。
请问我怎样才能完成这个任务?