PHP development corporate website tutorial showing information about us
After we have learned how to operate users (add, delete, modify, check), it will be very simple to develop the following functions. Most of them are the same, except that the SQL statements are different, but the principles are basically similar.
Below Let’s take a look at the display of some information about us
<?php
header("Content-type: text/html; charset=utf-8");//设置编码
require_once('conn.php');
$sql = "SELECT * FROM about order by id desc";
$res = mysql_query($sql);
//截取中文字符
function msubstr($str,$start=0,$length,$suffix=true,$charset="utf-8"){
if(function_exists("mb_substr")){
if ($suffix && mb_strlen($str, $charset)>$length)
return mb_substr($str, $start, $length, $charset)."...";
else
return mb_substr($str, $start, $length, $charset);
}elseif(function_exists('iconv_substr')) {
if ($suffix && strlen($str)>$length)
return iconv_substr($str,$start,$length,$charset)."...";
else
return iconv_substr($str,$start,$length,$charset);
}
$re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
$re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
$re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
$re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
preg_match_all($re[$charset], $str, $match);
$slice = join("",array_slice($match[0], $start, $length));
if($suffix) return $slice."…";
return $slice;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>展示关于我们的信息</title>
<style type="text/css">
.top{height:30px;line-height:30px;float:right;margin-right:15px;}
.top a{color:red;text-decoration:none;}
.cont{width:100%;height:300px;float:left;}
.cont_ct{float:left;}
table{width:100%;border:1px solid #eee;text-align:center;}
th{background:#eee;}
td{width:200px;height:40px;}
</style>
</head>
<body>
<div class="top"><a href="addab.php">添加信息</a></div>
<div class="cont">
<table cellspacing="0" cellpadding="0" border="1">
<tr>
<th>ID</th>
<th>标题</th>
<th>内容</th>
<th>操作</th>
</tr>
<?php
while($row = mysql_fetch_array($res)){
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['title'];?></td>
<td><!-- <textarea cols="50" rows="5" readonly> -->
<?php echo msubstr($row['content'],0,20);?><!-- </textarea> --></td>
<td>
<a href="modifya.php?id=<?php echo $row['id'];?>">修改</a>
<a href="delabout.php?id=<?php echo $row['id'];?>">删除</a>
</td>
</tr>
<?php
}
?>
</table>
</div>
</body>
</html>When the displayed content is too long, we need to intercept the length of the string
We have encapsulated the usage method Take a look at the code for the output content part below. Starting from 0, take 20
. Deletion and modification are also with id
new file
<?php
header("Content-type: text/html; charset=utf-8");//设置编码
require_once('conn.php');
$sql = "SELECT * FROM about order by id desc";
$res = mysql_query($sql);
//截取中文字符
function msubstr($str,$start=0,$length,$suffix=true,$charset="utf-8"){
if(function_exists("mb_substr")){
if ($suffix && mb_strlen($str, $charset)>$length)
return mb_substr($str, $start, $length, $charset)."...";
else
return mb_substr($str, $start, $length, $charset);
}elseif(function_exists('iconv_substr')) {
if ($suffix && strlen($str)>$length)
return iconv_substr($str,$start,$length,$charset)."...";
else
return iconv_substr($str,$start,$length,$charset);
}
$re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
$re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
$re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
$re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
preg_match_all($re[$charset], $str, $match);
$slice = join("",array_slice($match[0], $start, $length));
if($suffix) return $slice."…";
return $slice;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>展示关于我们的信息</title>
<style type="text/css">
.top{height:30px;line-height:30px;float:right;margin-right:15px;}
.top a{color:red;text-decoration:none;}
.cont{width:100%;height:300px;float:left;}
.cont_ct{float:left;}
table{width:100%;border:1px solid #eee;text-align:center;}
th{background:#eee;}
td{width:200px;height:40px;}
</style>
</head>
<body>
<div class="top"><a href="addab.php">添加信息</a></div>
<div class="cont">
<table cellspacing="0" cellpadding="0" border="1">
<tr>
<th>ID</th>
<th>标题</th>
<th>内容</th>
<th>操作</th>
</tr>
<?php
while($row = mysql_fetch_array($res)){
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['title'];?></td>
<td><!-- <textarea cols="50" rows="5" readonly> -->
<?php echo msubstr($row['content'],0,20);?><!-- </textarea> --></td>
<td>
<a href="modifya.php?id=<?php echo $row['id'];?>">修改</a>
<a href="delabout.php?id=<?php echo $row['id'];?>">删除</a>
</td>
</tr>
<?php
}
?>
</table>
</div>
</body>
</html>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















