languageexpand_more
English Deutsch Español Français Русский язык Italiano 한어 简体中文 繁體中文 日本語

(php)函数手册

  2015-01-12 © Sunplace,2015

 

[echo] 输出字符串,或者脚本(通常为Javascript)。

[print_r] 输出其他信息,通常用于打印数组。more例:

print_r($array_1);

[array] 创建数组。more例:

$a=array("Bill"=>"60");

[var_dump] 返回数据类型和十进制值。more

[strlen] 返回字符串长度。more

[strpos] 返回指定字符在字符串中的位置。例:

strpos('sold','s');//返回"s"在"sold"中的位置

[function]  定义一个函数,并设置参数默认值(内可以缺省)。例:

function test($s=5){/*your code here */}

[count] 获得数组的长度。

[substr_count] 统计字符串出现的次数。例:

substr_count('6c7c19c8c','c');

[htmlspecialchars] 把预定义的字符(&,’,”,<,>)转换为html实体。

[trim] 去除空格。

[stripslashes] 删除字符串中的“\”。

[isset] 判断变量是否被定义过。

[is_null] 判断变量是否为空值(null)。

[is_numeric] 判断变量是否可转化为数字。

[empty] 若变量已存在、非空字符串或者非零,则返回 false 值。

[preg_match] 正则表达式匹配,匹配返回true值。

例:

$urls = '<h3><a target="_blank" href="/php/preg_match.html"><span class="hl">preg</span>_match()</a></h3><p>[<a href="/Php.html">PHP</a>] 进行正则表达式匹配<br/><em>适用版本:5</em></p></dd><dd><h3><a target="_blank" href="/php/preg_match_all.html"><span class="hl">preg</span>_match_all()</a></h3>';
if(preg_match("/<a[^>]*?href=\"([^>]+?)\"[^>]*?>.+?<\/a>/i", $urls ,$match)) { 
  print_r($match); 
 } else { 
  echo "不匹配."; 
 }

[preg_replace] 正则替换。例:

$text = '<a href="https://kkii.org">导航</a>的地址是kkii.org,我们的邮箱为[email protected],欢迎交流。';
echo $text.'<br/>';
$text = preg_replace('/[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})/i','',$text);
echo $text.'<br/>';
$text = preg_replace('/((http|ftp|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?/i','',$text);
echo $text;

[date] 格式化时间。只有格式一个参数时,表示格式化当前时间。例:

date('Y-m-d');

[date_default_timezone_set] 设置默认时区。

[mktime返回一个日期的 Unix 时间戳,顺序为(时,分,秒,月,日,年),返回值为int型。例:

mktime(0,0,0,12,36,2001);

[strtotime] 函数用于把人类可读的字符串转换为 Unix 时间,返回类型为int。例:

strtotime("2009-10-21 16:00:10");

[die] 函数输出一条消息,并退出当前脚本。

[header] 跳转页面。例:

header('Location:/');//跳转到首页

[explode] 字符串打散为数组。more

[intval] 强制转换为int型。

[getimagesize] 获取图片的实际尺寸。more

[substr] 函数返回字符串的一部分。例:

echo substr("Hello world",6);//输出“world”

[stristr]  函数搜索字符串在另一字符串中的第一次出现。例:

echo stristr('Hello world!','0');//输出“o world!”

[file_exists] 判断文件是否存在。例:

if(file_exists('/upload/123.txt')){/*有文件123.txt*/}else{/*没有文件123.txt*/}

[unlink] 删除文件。例:

unlink('/upload/img.jpg');

[mkdir]  创建目录。

[is_dir]  判断目录是否存在。

[is_uploaded_file]  函数判断指定的文件是否是通过 HTTP POST 上传的。

[opendir]  打开目录。

[readdir]  读目录。

[move_uploaded_file]  将文件从临时文件夹移动到指定文件夹。

file_exists,unlink,mkdir,is_dir,is_uploaded_file,opendir,readdir,move_uploaded_file参考这里

[mysql_connect] 连接数据库。more

[mysql_query] 执行语句,返回结果集。例:

mysql_query("set names 'utf8'");//设置utf-8编码读数据库

[mysql_fetch_array] 遍历将结果集转换为数组。more

[mysql_num_rows] 取得结果集的行数。more

[mysql_error] 返回数据库执行的错误信息。more

[strip_tags] 删除所有html标签。例:

$text = '<a href="https://kkii.org">导航</a>的地址是kkii.org,我们的邮箱为[email protected],欢迎交流。';
echo strip_tags($text);

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

[smirking] [hentai] [wounded] [cracker] more »