php教程 strtotime()计算今天与指定日期之天数
$date1 = strtotime('2011-04-30'); //把日期转换成时间戳
$date2 = time(); //取当前时间的时间戳
$nowtime=strftime("%y年-%m月-%d日 ",$date2); //格式化输出日期
$days=round(($date1-$date2)/3600/24); //四舍五入
echo "今天是<font color="red">".$nowtime."</font>";
echo "<br/>距".strftime("%y年-%m月-%d日 ",$date1)."还有<font colr="red">".$days."</font>天";
echo date("y-m-d h:i:s",strtotime("now")). "<br />";
echo date("y-m-d h:i:s",strtotime("10 september 2000")). "<br />";
echo date("y-m-d h:i:s",strtotime("+2 day")). "<br />";
echo date("y-m-d h:i:s",strtotime("+1 week")). "<br />";
echo date("y-m-d h:i:s",strtotime("+1 week 2 days 4 hours 2 seconds")). "<br />";
echo date("y-m-d h:i:s",strtotime("next thursday")). "<br />";
echo date("y-m-d h:i:s",strtotime("last monday")). "<br />";
echo date("y-m-d h:i:s",strtotime("+3 day",strtotime('2001-01-01')));
检测数据类型php教程函数集
检测数据类型即对数据类型进行检测,判断所检测类型是否属于检测类型,符合则返回真,否则返回假。检测数据类型定义如下:
is_bool
是否为布尔类型,例,is_bool(srue) is_bool(false)
is_string
是否为字符串型,例,is_string(‘string’) is_string(1234)
is_float/double
是否为浮点型,例,is_float(3.1415) is_float(‘3.1415’)
is_integer/int
是否为整型,例,is_integer(34) is_integer(‘34’)
is_null
是否为空值,例,is_null(null)
is_array
是否为数组,例,is_array($arr)
is_object
是否为一个对象,例,is_object($obj)
is_numeric
是否为数字或由数字组成的字符串,例,is_numeric(‘5’) is_numeric(‘bcc110’)
示例
<?php
$boo="1234567890";
if(is_numeric($boo))
echo "变量boo属由数字组成的字符串类型:".$boo;
else
echo"无法判断";
?>
php教程中checkbox值获取,显示,多选值获取
最简单checkbox获取值代码
<html>
<head>
<title>checkbox demo</title>
</head>
<body>
<h1>checkbox demo</h1>
<h3>demonstrates checkboxes</h3>
<form action ="handleformcheckbox.php">
<ul>
<li><input type ="checkbox" name ="chkfries" value ="11.00">fries</li>
<li><input type ="checkbox" name ="chksoda" value ="12.85">soda</li>
<li><input type ="checkbox" name ="chkshake" value ="1.30">shake</li>
<li><input type ="checkbox" name ="chkketchup" value =".05">ketchup</li>
</ul>
<input type ="submit">
</form>
</body>
</html>
<!-- handleformcheckbox.php
<html>
<head>
<title>checkbox demo</title>
</head>
<body>
<h3>demonstrates reading checkboxes</h3>
<?
print <<<here
chkfries: $chkfries <br>
chksoda: $chksoda <br>
chkshake: $chkshake <br>
chkketchup: $chkketchup <br>
<hr>
here;
$total = 0;
if (!empty($chkfries)){
print ("you chose fries <br>");
$total = $total + $chkfries;
}
if (!empty($chksoda)){
print ("you chose soda <br>");
$total = $total + $chksoda;
}
if (!empty($chkshake)){
print ("you chose shake <br>");
$total = $total + $chkshake;
}
if (!empty($chkketchup)){
print ("you chose ketchup <br>");
$total = $total + $chkketchup;
}
print "the total cost is $$total";
?>
</body>
</html>
-->
实例
<html>
<head>
<title>using default checkbox values</title>
</head>
<body>
<?php
$food = $_get[food];
$self = htmlentities($_server['php_self']);
if (!empty($food)) {
echo "the foods selected are:<br />";
foreach($food as $foodstuf)
{
echo "<strong>".htmlentities($foodstuf)."</strong><br />";
}
}
else
{
echo ("<form action="$self" ");
echo ('method="get">
<fieldset>
<label>italian <input type="checkbox" name="food[]" value="italian" />
</label>
<label>mexican <input type="checkbox" name="food[]" value="mexican" />
</label>
<label>chinese <input type="checkbox" name="food[]" value="chinese"
checked="checked" /></label>
</fieldset>
<input type="submit" value="go!" >');
}
?>
</body>
</html>
多选checkbox
<?php
$options = array('option 1', 'option 2', 'option 3');
$valid = true;
if (is_array($_get['input'])) {
$valid = true;
foreach($_get['input'] as $input) {
if (!in_array($input, $options)) {
$valid = false;
}
}
if ($valid) {
//process input
}
}
?>
实例checkbox多值获取
<html>
<head>
<title>using default checkbox values</title>
</head>
<body>
<?php
$food = $_get["food"];
if (!empty($food)){
echo "the foods selected are: <strong>";
foreach($food as $foodstuff){
echo '<br />'.htmlentities($foodstuff);
}
echo "</strong>.";
}
else {
echo ('
<form action="'. htmlentities($_server["php_self"]).'" method="get">
<fieldset>
<label>
italian
<input type="checkbox" name="food[]" value="italian" />
</label>
<label>
mexican
<input type="checkbox" name="food[]" value="mexican" />
</label>
<label>
chinese
<input type="checkbox" name="food[]" value="chinese" checked="checked" />
</label>
</fieldset>
<input type="submit" value="go!" />
</form> ');
}
?>
</body>
</html>
$globals --- 保存所有全局变量(只在当前页面中的) get_defined_vars() --- 返回由所有已定义变量所组成的数组(包括全局变量,超全局变量等) get_defined_constants() --- 返回由所有已定义常量所组成的数组
function cleanglobal($global_array, $arg, $specialchars = true, $default = null) {
if(key_exists($arg, $global_array) && $global_array[$arg] != null && $global_array[$arg] != "") {
if($specialchars) {
return htmlspecialchars($global_array[$arg]);
} else {
return $global_array[$arg];
}
} else {
return $default;
}
}
table of contents
superglobals — superglobals are built-in variables that are always available in all scopes
$globals — references all variables available in global scope
$_server — server and execution environment information
$_get — http get variables
$_post — http post variables
$_files — http file upload variables
$_request — http request variables
$_session — session variables
$_env — environment variables
$_cookie — http cookies
$php教程_errormsg — the previous error message
$http_raw_post_data — raw post data
$http_response_header — http response headers
$argc — the number of arguments passed to script
$argv — array of arguments passed to script
使用substr_count()函数检索字符出现的次数
获取指定字符在字符串中出现的次数
语法:substr_count(haystack,needle)
使用substr_count()函数获取特定字符在字符串中出现的次数实例如下:
<?php教程
echo substr_count(“zero的php自学手册”,”的”);
echo “<br>”;
echo substr_count(“www.111cn.net”,”o”);
echo “<br>”;
echo substr_count(“1033114118′,”1′);
?>
实例结果:
1
2
5
参数 | 描述 |
---|---|
string | 必需。规定要检查的字符串。 |
replacement | 必需。规定要插入的字符串。 |
start | 可选。规定在字符串中何处开始搜索。 |
charlist | 可选。规定搜索的长度。 |