우리에 대한 정보를 보여주는 PHP 개발 기업 웹사이트 튜토리얼
사용자 조작 방법(추가, 삭제, 수정, 확인)을 배운 후에는 다음 기능을 개발하는 것이 매우 간단할 것입니다. SQL 문이 다르다는 점만 제외하면 대부분 동일하지만 기본적으로 원칙은 같습니다. 유사
다음을 살펴보겠습니다. 일부 정보 표시에 관해
<?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>표시된 내용이 너무 길면 문자열 길이를 가로채야 합니다
이것을 사용하는 방법을 캡슐화했습니다. 0부터 시작하는 아래 출력 콘텐츠 부분의 코드를 살펴보세요. Take 20
삭제 및 수정에도 ID가 있습니다
새로운 파일
<?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>
시사
Clear
- 코스 추천
- 코스웨어 다운로드
현재 코스웨어를 다운로드할 수 없습니다. 현재 직원들이 정리하고 있습니다. 앞으로도 본 강좌에 많은 관심 부탁드립니다~
이 강좌를 시청한 학생들도 학습하고 있습니다.
PHP로 사업을 시작하는 방법에 대해 간단히 이야기해 보겠습니다.
웹 프론트 엔드 개발에 대한 빠른 소개
민망한 물건 백과사전 사이트를 모방한 Mini 버전 MVC 프레임워크의 대규모 실용 Tianlongbabu 개발
PHP 실용 개발 시작하기: 빠른 PHP 생성 [중소기업 포럼]
로그인 인증 및 클래식 게시판
컴퓨터 네트워크 지식 수집
빠른 시작 Node.JS 정식 버전
당신을 가장 잘 이해하는 프론트엔드 강좌: HTML5/CSS3/ES6/NPM/Vue/...[원본]
자신만의 PHP MVC 프레임워크 작성(깊이 있는 40개 장/자세한 내용/초보자가 발전하려면 읽어야 함)
















