例1,根据指定的日期生成时间戳,checkdate检测日期
echo("Validating: 5/31/2013<br />");
if (checkdate(5,31,2007)) {
echo('Date accepted: ');
$new_date=mktime(18,05,35,5,31,2013);
echo date("r",$new_date);
}
else {
echo ('Invalid date.');
}
//by www.
?>
2,checkdate()日期检测
<?php
echo checkdate(4, 31, 2005);
echo checkdate(03, 29, 2004);
echo checkdate(03, 29, 2005);
?>
例1,格式化数字为文本
print number_format(100000.56 );
?>
例2,number_format($n, $p, $t, $d) rounds $n to $p decimal places, using $t as the thousands separator and $d as the decimal separator.
echo "Total charge is ", number_format($total, 2, ".", ","), " Euros";
?>
例3,number_format函数用于English format and Italian format
<?php
$a = 1232322210.44;
echo number_format ($a, 2); // English format
echo "\n";
echo number_format ($a, 2, ',', '.'); // Italian format
echo "\n";
?>
例4,输出格式化的数字形式
print "The population of the US is about:";
print number_format(285266237);
?>
例1,检查PHP的全局身份验证变量
if ( (! isset() ($PHP_AUTH_USER)) || (! isset ($PHP_AUTH_PW)) ):
header('WWW-Authenticate: Basic realm="Secret Family"');
header('HTTP/1.0 401 Unauthorized');
print "Authorization is required.";
exit;
endif;
?>
例2,isset()检查一个变量是否设置值
<?
$foo = 1;
if (isset($foo)) {
echo "Foo is set\n";
} else {
echo "Foo is not set\n";
}
if (isset($bar)) {
echo "Bar is set\n";
} else {
echo "Bar is not set\n";
}
?>
例3,查看用户cookie,学习下isset()的用法
<?php
setcookie("username","michele");
echo 'Cookie created.';
if (!isset($_COOKIE['username'])){
echo ("Oops, the cookie isn't set!");
}else{
echo ("The stored username is ". $_COOKIE['username'] . ".");
}
?>
例4,isset()函数查看数组元素是否定义
$array = array('a' => 'R', 'b' => 2, c => '2');
print "<p>Using for:</p>\n<p>";
$limit = count($array);
for($i = 0; $i < $limit; $i++)
if( isset($array[$i]) )
printf("· %s,", $array[$i]);
?>
您可能感兴趣的文章:
PHP 函数 isset、array_key_exists 的差异实例解析PHP中empty,is_null和isset的用法区别
php编程基础之isset与empty
实例学习php中isset与array_key_exists的区别
php中array_key_exists与isset的区别
php empty(),isset()与is_null()的用法区别分析
php empty()与isset()函数区别分析
php 中 empty 和 isset 的区别
php isset 函数的用法
empty()和isset()函数的区别