$row=mb_substr(htmlspecialchars(strip_tags($latestnews['content'])),0,26,'UTF-8')
如果想把<script></script>之间的也去掉,只能正则了:
$str = preg_replace("|<script.*>.*</script>|Usi", '', $str)
$con=mysql_connect('localhost','root','')//数据库信息mysql_select_db('shop')//数据库名
mysql_query("set names utf8")//设置字符集编码
$sql="select goods_name,goods_number,shop_price from goods"//查询语句
$res=mysql_query($sql)//执行查询
while($row=mysql_fetch_assoc($res)){
$rows[]=$row//接受结果集
}
//遍历数组
foreach($rows as $key=>$v){
echo $v['goods_name']."---".$v['goods_number']."---".$v['shop_price'].""
}
试编写代码如下:
<?php//从数据库根据 id 获取颜色
function getColor($db, $id)
{
if ($result = $db->query("SELECT * FROM color where id='" . $id . "'"))
{
$row = $result->fetch_assoc()
return $row['color']
}
return '#000000'
}
$mysqli = new mysqli("localhost", "test", "test", "room")
if ($mysqli->connect_error) {
printf("数据库连接错误: %s\n", mysqli_connect_error())
exit()
}
?>
<table border="1" cellspacing="0">
<tr>
<td bgcolor="<?php echo getColor($mysqli,'1')?>">1</td>
</tr>
<tr>
<td bgcolor="<?php echo getColor($mysqli,'2')?>">2</td>
</tr>
<tr>
<td bgcolor="<?php echo getColor($mysqli,'3')?>">3</td>
</tr>
</table>
<?php
$mysqli->close()
?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)