PHP用户验证和标签推荐的简单使用

本文给大家讲解一些最简单的验证知识。大家可以先看下效果图,如果大家感觉还不错,请参考实现代码。

效果图

bookmark_fns.php

<?php
require_once('output_fns.php');
require_once('db_fns.php');
require_once('data_valid_fns.php');
require_once('url_fns.php');
require_once('user_auth_fns.php');
?>

data_valid_fns.php

<?php
// Test that each variable has a value
function filled_out($form_vars) {
foreach ($form_vars as $key => $value) {
if ((!isset($key)) || ($value == '')) {
return false;
}
}
return true;
}
// Valid email
function valid_email($address) {
if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $address)) {
return true;
}else {
return false;
}
}
?>

db_fns.php

<?php
//Conncet to db
function db_connect() {
$db = new mysqli('127.0.0.1', 'bm_user', 'password', 'bookmarks');
if (!$db) {
throw new Exception("Could not connect to database server", 1);
}else {
return $db;
}
}
?>

user_auth_fns.php

<?php
require_once('db_fns.php');
// register
function register($username, $email, $password) {
$conn = db_connect();
$results = $conn -> query("select * from user where username = '".$username."'");
if (!$results) {
throw new Exception("Could not execute query", 1);
}
if ($results -> num_rows > 0) {
throw new Exception("That username is taken - go back and choose another one.", 1);
}
$results = $conn -> query("insert into user values ('".$username."', sha1('".$email."'), '".$password."')");
if (!$results) {
throw new Exception('Could not register you in database - please try again later.');
}
return true;
}
// Log in
function login($username, $password) {
$conn = db_connect();
$results = $conn -> query("select * from user where username = '".$username."' and passwd = sha1('".$password."')");
if (!$results) {
throw new Exception('Could not log you in.');
}
if ($results -> num_rows > 0) {
return true;
}else {
throw new Exception('Could not log you in.');
}
}
// Check valid user
function check_valid_user() {
if (isset($_SESSION['valid_user'])) {
echo "Logged in as ".$_SESSION['valid_user'].".<br />";
}else {
do_html_header('Problem:');
echo "You are not logged in.<br />";
do_html_url('login.php', 'Login');
do_html_foot();
exit;
}
}
// change password
function change_password($username, $old_password, $new_password) {
login($username, $old_password);
$conn = db_connect();

$result = $conn -> query("update user set passwd = sha1('".$new_password."') where username = '".$username."'");
if (!$result) {
throw new Exception('Password could not be changed.');
} else {
return true; // changed successfully
}
}
function get_random_word($min_length, $max_length) {
// grab a random word from dictionary between the two lengths
// and return it
// generate a random word
$word = '';
// remember to change this path to suit your system
$dictionary = '/usr/dict/words'; // the ispell dictionary
$fp = @fopen($dictionary, 'r');
if(!$fp) {
return false;
}
$size = filesize($dictionary);
// go to a random location in dictionary
$rand_location = rand(0, $size);
fseek($fp, $rand_location);
// get the next whole word of the right length in the file
while ((strlen($word) < $min_length) || (strlen($word)>$max_length) || (strstr($word, "'"))) {
if (feof($fp)) {
fseek($fp, 0); // if at end, go to start
}
$word = fgets($fp, 80); // skip first word as it could be partial
$word = fgets($fp, 80); // the potential password
}
$word = trim($word); // trim the trailing \n from fgets
return $word;
}
function reset_password($username) {
// set password for username to a random value
// return the new password or false on failure
// get a random dictionary word b/w 6 and 13 chars in length
$new_password = get_random_word(6, 13);

if($new_password == false) {
throw new Exception('Could not generate new password.');
}
// add a number between 0 and 999 to it
// to make it a slightly better password
$rand_number = rand(0, 999);
$new_password .= $rand_number;
// set user's password to this in database or return false
$conn = db_connect();
$result = $conn->query("update user
set passwd = sha1('".$new_password."')
where username = '".$username."'");
if (!$result) {
throw new Exception('Could not change password.'); // not changed
} else {
return $new_password; // changed successfully
}
}
function notify_password($username, $password) {
// notify the user that their password has been changed
$conn = db_connect();
$result = $conn->query("select email from user
where username='".$username."'");
if (!$result) {
throw new Exception('Could not find email address.');
} else if ($result->num_rows == 0) {
throw new Exception('Could not find email address.');
// username not in db
} else {
$row = $result->fetch_object();
$email = $row->email;
$from = "From: support@phpbookmark \r\n";
$mesg = "Your PHPBookmark password has been changed to ".$password."\r\n"
."Please change it next time you log in.\r\n";
if (mail($email, 'PHPBookmark login information', $mesg, $from)) {
return true;
} else {
throw new Exception('Could not send email.');
}
}
}
?>

url_fns.php

<?php
require_once('db_fns.php');
// Get user urls
function get_user_urls($username) {
$conn = db_connect();
$results = $conn -> query("select bm_URL
from bookmark
where username = '" . $username . "'");
if (!$results) {
return false;
}
$url_array = array();
for ($i = 1;$row = $results -> fetch_row();++$i) {
$url_array[$i] = $row[0];
}
return $url_array;
}
// Add url to db
function add_bm($new_url) {
echo "Attempting to add ".htmlspecialchars($new_url)."<br />";
$valid_user = $_SESSION['valid_user'];
$conn = db_connect();
$results = $conn -> query(" select * from bookmark
where username = '".$valid_user."'
and bm_URL = '".$new_url."'");
if ($results && ($results -> num_rows > 0)) {
throw new Exception("Bookmark already exists.", 1);
}
$insert_result = $conn -> query("insert into bookmark values ('".$valid_user."', '".addslashes($new_url)."')");
if (!$insert_result) {
throw new Exception("Bookmark could not be inserted.", 1);
}
return true;
}
// Delete url
function delete_bm($user, $url) {
$conn = db_connect();
$results = $conn -> query(" delete from bookmark
where username = '".$user."'
and bm_URL = '".$url."'");
if (!$results) {
throw new Exception("Bookmark could not be deleted.", 1);
}
return true;
}
function recommend_urls($valid_user, $popularity = 1) {
$conn = db_connect();
// $query = "select bm_URL
// from bookmark
// where username in
// (select distinct(b2.username)
// from bookmark b1, bookmark b2
// where b1.username='".$valid_user."'
// and b1.username != b2.username
// and b1.bm_URL = b2.bm_URL)
// and bm_URL not in
// (select bm_URL
// from bookmark
// where username='".$valid_user."')
// group by bm_url
// having count(bm_url)>".$popularity;
$query = "select bm_URL
from bookmark
where username in
(select distinct(b2.username)
from bookmark b1, bookmark b2
where b1.username='".$valid_user."'
and b1.username != b2.username
and b1.bm_URL = b2.bm_URL)
and bm_URL not in
(select bm_URL
from bookmark
where username='".$valid_user."')
group by bm_url
having count(bm_url)>".$popularity;
if (!($result = $conn->query($query))) {
throw new Exception('Could not find any bookmarks to recommend.');
}
if ($result->num_rows==0) {
throw new Exception('Could not find any bookmarks to recommend.');
}
$urls = array();
// build an array of the relevant urls
for ($count=0; $row = $result->fetch_object(); $count++) {
$urls[$count] = $row->bm_URL;
}
return $urls;
}
?>

output_fns.php

<?php
function do_html_header($title) {
// print an HTML header
?>
<html>
<head>
<title><?php echo $title;?></title>
<style>
body { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
hr { color: #3333cc; width=300; text-align=left}
a { color: #000000 }
</style>
</head>
<body>
<img src="005.png" alt="PHPbookmark logo" border="0"
align="left" valign="bottom" height="55" width="57" />
<h1>PHPbookmark</h1>
<hr />
<?php
if($title) {
do_html_heading($title);
}
}
function do_html_footer() {
// print an HTML footer
?>
</body>
</html>
<?php
}
function do_html_heading($heading) {
// print heading
?>
<h2><?php echo $heading;?></h2>
<?php
}
function do_html_URL($url, $name) {
// output URL as link and br
?>
<br /><a href="<?php echo $url;?>"><?php echo $name;?></a><br />
<?php
}
function display_site_info() {
// display some marketing info
?>
<ul>
<li>Store your bookmarks online with us!</li>
<li>See what other users use!</li>
<li>Share your favorite links with others!</li>
</ul>
<?php
}
function display_login_form() {
?>
<p><a href="register_form.php">Not a member?</a></p>
<form method="post" action="member.php">
<table bgcolor="#cccccc">
<tr>
<td colspan="2">Members log in here:</td>
<tr>
<td>Username:</td>
<td><input type="text" name="username"/></td></tr>
<tr>
<td>Password:</td>
<td><input type="password" name="passwd"/></td></tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Log in"/></td></tr>
<tr>
<td colspan="2"><a href="forgot_form.php">Forgot your password?</a></td>
</tr>
</table></form>
<?php
}
function display_registration_form() {
?>
<form method="post" action="register_new.php">
<table bgcolor="#cccccc">
<tr>
<td>Email address:</td>
<td><input type="text" name="email" size="30" maxlength="100"/></td></tr>
<tr>
<td>Preferred username <br />(max 16 chars):</td>
<td valign="top"><input type="text" name="username"
size="16" maxlength="16"/></td></tr>
<tr>
<td>Password <br />(between 6 and 16 chars):</td>
<td valign="top"><input type="password" name="passwd"
size="16" maxlength="16"/></td></tr>
<tr>
<td>Confirm password:</td>
<td><input type="password" name="passwd2" size="16" maxlength="16"/></td></tr>
<tr>
<td colspan=2 align="center">
<input type="submit" value="Register"></td></tr>
</table></form>
<?php
}
function display_user_urls($url_array) {
// display the table of URLs
// set global variable, so we can test later if this is on the page
global $bm_table;
$bm_table = true;
?>
<br />
<form name="bm_table" action="delete_bms.php" method="post">
<table width="300" cellpadding="2" cellspacing="0">
<?php
$color = "#cccccc";
echo "<tr bgcolor=\"".$color."\"><td><strong>Bookmark</strong></td>";
echo "<td><strong>Delete?</strong></td></tr>";
if ((is_array($url_array)) && (count($url_array) > 0)) {
foreach ($url_array as $url) {
if ($color == "#cccccc") {
$color = "#ffffff";
} else {
$color = "#cccccc";
}
//remember to call htmlspecialchars() when we are displaying user data
echo "<tr bgcolor=\"".$color."\"><td><a href=\"".$url."\">".htmlspecialchars($url)."</a></td>
<td><input type=\"checkbox\" name=\"del_me[]\"
value=\"".$url."\"/></td>
</tr>";
}
} else {
echo "<tr><td>No bookmarks on record</td></tr>";
}
?>
</table>
</form>
<?php
}
function display_user_menu() {
// display the menu options on this page
?>
<hr />
<a href="member.php">Home</a>  | 
<a href="add_bm_form.php">Add BM</a>  | 
<?php
// only offer the delete option if bookmark table is on this page
global $bm_table;
if ($bm_table == true) {
echo "<a href=\"#\" onClick=\"bm_table.submit();\">Delete BM</a>  | ";
} else {
echo "<span style=\"color: #cccccc\">Delete BM</span>  | ";
}
?>
<a href="change_passwd_form.php">Change password</a>
<br />
<a href="recommend.php">Recommend URLs to me</a>  | 
<a href="logout.php">Logout</a>
<hr />
<?php
}
function display_add_bm_form() {
// display the form for people to ener a new bookmark in
?>
<form name="bm_table" action="add_bms.php" method="post">
<table width="250" cellpadding="2" cellspacing="0" bgcolor="#cccccc">
<tr><td>New BM:</td>
<td><input type="text" name="new_url" value="http://"
size="30" maxlength="255"/></td></tr>
<tr><td colspan="2" align="center">
<input type="submit" value="Add bookmark"/></td></tr>
</table>
</form>
<?php
}
function display_password_form() {
// display html change password form
?>
<br />
<form action="change_passwd.php" method="post">
<table width="250" cellpadding="2" cellspacing="0" bgcolor="#cccccc">
<tr><td>Old password:</td>
<td><input type="password" name="old_passwd"
size="16" maxlength="16"/></td>
</tr>
<tr><td>New password:</td>
<td><input type="password" name="new_passwd"
size="16" maxlength="16"/></td>
</tr>
<tr><td>Repeat new password:</td>
<td><input type="password" name="new_passwd2"
size="16" maxlength="16"/></td>
</tr>
<tr><td colspan="2" align="center">
<input type="submit" value="Change password"/>
</td></tr>
</table>
<br />
<?php
}
function display_forgot_form() {
// display HTML form to reset and email password
?>
<br />
<form action="forgot_passwd.php" method="post">
<table width="250" cellpadding="2" cellspacing="0" bgcolor="#cccccc">
<tr><td>Enter your username</td>
<td><input type="text" name="username" size="16" maxlength="16"/></td>
</tr>
<tr><td colspan=2 align="center">
<input type="submit" value="Change password"/>
</td></tr>
</table>
<br />
<?php
}
function display_recommended_urls($url_array) {
// similar output to display_user_urls
// instead of displaying the users bookmarks, display recomendation
?>
<br />
<table width="300" cellpadding="2" cellspacing="0">
<?php
$color = "#cccccc";
echo "<tr bgcolor=\"".$color."\">
<td><strong>Recommendations</strong></td></tr>";
if ((is_array($url_array)) && (count($url_array)>0)) {
foreach ($url_array as $url) {
if ($color == "#cccccc") {
$color = "#ffffff";
} else {
$color = "#cccccc";
}
echo "<tr bgcolor=\"".$color."\">
<td><a href=\"".$url."\">".htmlspecialchars($url)."</a></td></tr>";
}
} else {
echo "<tr><td>No recommendations for you today.</td></tr>";
}
?>
</table>
<?php
}
?>
login.php
<?php
require_once('bookmark_fns.php');
do_html_header('');
display_site_info();
display_login_form();
do_html_footer();
?>
logout.php
<?php

require_once('bookmark_fns.php');

// start session
session_start();
$old_user = $_SESSION['valid_user'];
unset($_SESSION['valid_user']);
$result_dest = session_destroy();
do_html_header('Logging out');
if (!empty($old_user)) {
if ($result_dest) {
echo 'Logged out.<br />';
do_html_url('login.php', 'Login');
}else {
echo 'Could not log you out.<br />';
}
}else {
echo 'You are not logged in ,so have not been logged out.<br />';
do_html_url('login.php', 'Login');
}
do_html_footer();
?>

register_form.php

<?php
require_once('bookmark_fns.php');
do_html_header('User Registration');
display_registration_form();
do_html_footer();
?>
register_new.php
<?php
require_once('bookmark_fns.php');
// vars
$email = $_POST['email'];
$username = $_POST['username'];
$passwd = $_POST['passwd'];
$passwd2 = $_POST['passwd2'];
// start session
session_start();
// valid data
try {
if (!filled_out($_POST)) {
throw new Exception("You have not filled the form out correctly - please go back and try again.", 1);
}
if (!valid_email($email)) {
throw new Exception("That is not a valid email address - please go back and try again.", 1);
}
if ($passwd != $passwd2) {
throw new Exception("The passwords you entered do not match - please go back and try again.", 1);
}
if ((strlen($passwd) < 6) || (strlen($passwd) > 16)) {
throw new Exception("Your password must be between 6 and 16 characters - please go back and try again.", 1);
}
register($username, $passwd, $email);
$_SESSION['valid_user'] = $username;
do_html_header('Rigistration successful');
do_html_url('member.php', 'Go to members page');
do_html_footer();
} catch (Exception $e) {
do_html_header('Problem: ');
echo $e -> getMessage();
do_html_footer();
exit();
}
?>

forgot_form.php

<?php
require_once('bookmark_fns.php');
do_html_header('Reset password');
display_forgot_form();
do_html_footer();
?>
forgot_passwd.php
<?php
require_once('bookmark_fns.php');
do_html_header('Resetting password');
$username = $_POST['username'];
try {
// get random password
$password = reset_password($username);
notify_password($username, $password);
echo "Your new password has been emailed to you.<br />";
}catch(Exception $e){
echo "Your password could not be reset - please try again later.";
}
do_html_url('login.php', 'Login');
do_html_footer();
?>
change_passwd_form.php
<?php
require_once('bookmark_fns.php');
session_start();
do_html_header('Change password');
check_valid_user();
display_password_form();
display_user_menu();
do_html_footer();
?>
change_passed.php
<?php
require_once('bookmark_fns.php');
session_start();
do_html_header('Changing password');
$old_passwd = $_POST['old_passwd'];
$new_passwd = $_POST['new_passwd'];
$new_passwd2 = $_POST['new_passwd2'];
try {
check_valid_user();
if (!filled_out($_POST)) {
throw new Exception("You have not filled the form out correctly - please go back and try again.", 1);
}
if ($new_passwd != $new_passwd2) {
throw new Exception("The passwords you entered do not match - please go back and try again.", 1);
}
if ((strlen($new_passwd) < 6) || (strlen($new_passwd) > 16)) {
throw new Exception("Your password must be between 6 and 16 characters - please go back and try again.", 1);
}
change_password($_SESSION['valid_user'], $old_passwd, $new_passwd2);
echo 'Password changed.';
}catch(Exception $e) {
echo $e -> getMessage();
}
display_user_menu();
do_html_footer();
?>
add_bm_form.php
<?php
// include function files for this application
require_once('bookmark_fns.php');
session_start();
// start output html
do_html_header('Add Bookmarks');
check_valid_user();
display_add_bm_form();
display_user_menu();
do_html_footer();
?>

add_bms.php

<?php
require_once('bookmark_fns.php');
session_start();
$new_url = $_POST['new_url'];
do_html_header('Adding bookmarks');
try {
check_valid_user();
if (!filled_out($_POST)) {
throw new Exception('Form not completely filled out.');
}
if (strstr($new_url, 'http://') === false) {
$new_url = 'http://'.$new_url;
}
// check url is valid
if (!@fopen($new_url, 'r')) {
throw new Exception('Not a valid URL.');
}
add_bm($new_url);
echo "Bookmark added";
if ($mks = get_user_urls($_SESSION['valid_user'])) {
display_user_urls($mks);
}
}catch(Exception $e) {
echo $e -> getMessage();
}
display_user_menu();
do_html_footer();
?>

delete_bms.php

<?php
require_once('bookmark_fns.php');
session_start();
$del_me = $_POST['del_me'];
$valid_user = $_SESSION['valid_user'];
do_html_header('Deleting bookmarks');
check_valid_user();
if (!filled_out($_POST)) {
echo "<p>You have not chosen any bookmarks to delete.<br />
Please try again.</p>";
display_user_menu();
do_html_footer();
exit;
}else {
if (count($del_me) > 0) {
foreach ($del_me as $url) {
if (delete_bm($valid_user, $url)) {
echo "Deleted ".htmlspecialchars($url)."<br />";
}else {
echo "Could not deleted ".htmlspecialchars($url)."<br />";
}
}
}else {
echo "No bookmarks selected for deletion.";
}
}
if ($mks = get_user_urls($_SESSION['valid_user'])) {
display_user_urls($mks);
}
display_user_menu();
do_html_footer();
?>

recommend.php

<?php
require_once('bookmark_fns.php');

session_start();
do_html_header('Recommending URLS');
try {
check_valid_user();
$urls = recommend_urls($_SESSION['valid_user'], 1);
display_recommended_urls($urls);
}catch(Exception $e) {
echo $e -> getMessage();
}
display_user_menu();
do_html_footer();
?>

member.php

<?php
require_once('bookmark_fns.php');
session_start();
@$username = $_POST['username'];
@$passwd = $_POST['passwd'];
if ($username && $passwd) {
try {
// Log in
login($username, $passwd);
$_SESSION['valid_user'] = $username;
}catch(Exception $e) {
do_html_header('Problem: ');
echo "You could not be logged in. You must be logged in to view this page.";
do_html_url('login.php', 'Login');
do_html_footer();
exit;
}
}
do_html_header('Home');
check_valid_user();
if ($url_array = get_user_urls($_SESSION['valid_user'])) {
display_user_urls($url_array);
}
display_user_menu();
do_html_footer();
?>

以上所述是小编给大家介绍的PHP用户验证和标签推荐的简单使用,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!

(0)

相关推荐

  • php array_pop 删除数组最后一个元素实例

    php array_pop函数将数组最后一个单元弹出(出栈),即删除数组的最后一个元素.本文章通过php实例向大家讲解array_pop函数的使用方法. array_pop - 将数组最后一个单元弹出(出栈) 说明 mixed array_pop ( array &$array ) array_pop() 弹出并返回 array 数组的最后一个单元,并将数组 array 的长度减一.如果 array 为空(或者不是数组)将返回 NULL . 此外如果被调用不是一个数则会产生一个 Warning.

  • PHPCMS忘记后台密码的解决办法

    什么是PHPCMS? PHPCMS是一款网站管理软件.该软件采用模块化开发,支持多种分类方式,使用它可方便实现个性化网站的设计.开发与维护.它支持众多的程序组合,可轻松实现网站平台迁移,并可广泛满足各种规模的网站需求,可靠性高,是一款具备文章.下载.图片.分类信息.影视.商城.采集.财务等众多功能的强大.易用.可扩展的优秀网站管理软件. PHPCMS后台密码忘记解决办法,本文主要是从技术角度去解决的,请细看正文. 1. 密码忘记就得先找到加密的方法了 1.1 PHPCMS密码只能重试8次,超过重

  • PHP递归获取目录内所有文件的实现方法

    如下所示: /** * 递归获取文件夹内所有文件 * 返回一个TREE结构的文件系统 * @param string $dir * @param array $filter * @return array $files */ function scan_dir($dir, $filter = array()){ if(!is_dir($dir))return false; $files = array_diff(scandir($dir), array('.', '..')); if(is_ar

  • PHP之十六个魔术方法详细介绍

    PHP中把以两个下划线__开头的方法称为魔术方法(Magic methods),这些方法在PHP中充当了举足轻重的作用. 魔术方法包括: __construct(),类的构造函数 __destruct(),类的析构函数 __call(),在对象中调用一个不可访问方法时调用 __callStatic(),用静态方式中调用一个不可访问方法时调用 __get(),获得一个类的成员变量时调用 __set(),设置一个类的成员变量时调用 __isset(),当对不可访问属性调用isset()或empty(

  • PHP实现小偷程序实例

    为什么使用"小偷程序"? 远程抓取文章资讯或商品信息是很多企业要求程序员实现的功能,也就是俗说的小偷程序.其最主要的优点是:解决了公司网编繁重的工作,大大提高了效率.只需要一运行就能快速的抓取别人网站的信息. "小偷程序"在哪里运行? "小偷程序" 应该在 Windows 下的 DOS或 Linux 下通过 PHP 命令运行为最佳,因为,网页运行会超时. 比如图(Windows 下 DOS 为例): "小偷程序"的实现 这里主

  • PHP仿微信发红包领红包效果

    近期项目需要在聊天的基础上新增红包功能,需求:仿微信(不含留言),但只能使用余额发红包.于是多次使用微信红包,了解各种交互界面及业务需求,如展示信息.分类(个人,群普通,群拼手气).个数限制(100).金额限制(200).过期时间(24小时)等等,然后着手开发,下面提及的基本全是提供给app端的接口,毕竟我是phper. 一.设计数据表如下 CREATE TABLE `red_packet` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `us

  • php将服务端的文件读出来显示在web页面实例

    本篇文章的内容我将告诉你如何应用php将服务端的文件读出来显示在web页面. 现有保存在服务端的文件orders.txt,内容为: 现创建vieworder.PHP文件,将其读出并显示; <?php $DOCUMENT_ROOT =$_SERVER['DOCUMENT_ROOT']; ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>客户订

  • php 实现一个字符串加密解密的函数实例代码

    php 实现一个字符串加密解密的函数 函数代码如下: /********************************************************************* 函数名称:encrypt 函数作用:加密解密字符串 使用方法: 加密 :encrypt('str','E','nowamagic'); 解密 :encrypt('被加密过的字符串','D','nowamagic'); 参数说明: $string :需要加密解密的字符串 $operation:判断是加密还

  • php array_pop()数组函数将数组最后一个单元弹出(出栈)

    复制代码 代码如下: <?php /*函数array_pop():将数组最后一个单元弹出(出栈) * 1.语法:mixed array_pop ( array &array ) * 2.描述: 弹出并返回 array 数组的最后一个单元,并将数组 array 的长度减一.如果 array 为空(或者不是数组)将返回 NULL. * 3.注意事项: * 3.1. */ echo "****************************************************

  • php数组函数序列之array_pop() - 删除数组中的最后一个元素

    array_pop()定义和用法 array_pop() 函数删除数组中的最后一个元素. 语法 array_pop(array)参数 描述 array 必需.规定输入的数组参数. 例子 复制代码 代码如下: <?php $a=array("Dog","Cat","Horse"); array_pop($a); print_r($a); ?> 输出: Array ( [0] => Dog [1] => Cat )

  • 利用php做服务器和web前端的界面进行交互

    PHP与Web页面交互是实现PHP网站与用户交互的重要手段.希望查看本篇文章的学者首先查看一下PHP的基础知识,因为今天用到这个东西,现学现卖吧.后续会更新php服务器的基础知识! 1.首先你要有一个界面   我这里利用我项目开发的一个简单界面截取下来进行讲解!项目机密  请勿**,你懂得! html代码和界面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or

随机推荐