首页 > PHP教程

php 查找字符串中单词个数

*/
$str="hello world";          //定义字符串
$result=str_word_count($str);        //查找单词个数
echo $result;           //输出的结果
echo "<br>";
$result=str_word_count($str,1);        //返回数组
print_r($result);           //输出结果数组

阅读全文

php 数组查找关键函数

$crud = array('中国|||我国|||大地', 'kelon|||lerke|||sb', 'sesscxx');
$crud = join('|',$crud);
$crud = str_replace('|||', '|', $crud);
$pat  = "/({$crud})/i";
$txt = '我知道中国你是sdfex谁!!';
preg_match/*_all*/($pat, $txt, $matches);
var_dump($matches);

阅读全文

php printf函数格式化详细说明(1/2)

语法
printf(format,arg1,arg2,arg++)参数 描述
format 必需。规定字符串以及如何格式化其中的变量。
arg1 必需。规定插到格式化字符串中第一个 % 符号处的参数。
arg2 可选。规定插到格式化字符串中第二个 % 符号处的参数。
arg++ 可选。规定插到格式化字符串中第三、四等等 % 符号处的参数。

阅读全文

php分割字符串函数

chunk_split() 函数把字符串分割为一连串更小的部分。

语法
chunk_split(string,length,end)参数 描述
string 必需。规定要分割的字符串。
length 可选。一个数字,定义字符串块的长度。
end 可选。字符串值,定义在每个字符串块之后放置的内容。

阅读全文

php addslashes sql防注入函数

//参数'a..z'界定所有大小写字母均被转义
echo addcslashes('foo[ ]','a..z');       //输出:foo[ ]

//
$str="is your name o'reilly?";      //定义字符串,其中包括需要转义的字符
echo addslashes($str);       //输出经过转义的字符串

阅读全文