$temp[0]="abc";
$temp[1]=123;
$temp[2]="us.";
$temp[3]=5;
$temp[4]=58;
$temp[5]="cs";
//以上代码定义一个数组,其中既有数字也有字符串
echo "数组temp的内容为:";
echo "<p>";
//通过循环输出数组内容
for($i=0;$i<count($temp);$i++)
{
echo $temp[$i];
echo ",";
}
echo "<p>";
echo "经过preg_grep()处理过之后的新数组为:";
$temp2=preg_grep("/^(d)d*/",$temp); //使用preg_grep进行处理
//上式的正则表达式模式中"//"为定界符,其内容为所有整数元素
echo "<p>";
print_r($temp2); //通过循环输出新数组内容
php中正则获取url函数preg_match
$string="<b>example:</b><div align=left>this is a test</div>"; //定义字符串
$pattern="|<[^>]+>(.*)</[^>]+>|u"; //定义正则表达式模式
/*该匹配模式的意义是:以"<"开头后面跟1到多个不为">"的字符加上结尾内容;子模式中的".*"表示0到多个任意字符,再加上以"<"开头后面跟1到多个不为">"的字符加上">"符号。*/
preg_match_all($pattern,$string,$out,preg_pattern_order); //进行preg_mathc_all处理
echo $out[0][0];
echo ",";
echo $out[0][1];
echo "<p>";
echo $out[1][0];
echo ",";
echo $out[1][1];
php中字符查找函数
stristr() 函数查找字符串在另一个字符串中第一次出现的位置。
如果成功,则返回字符串的其余部分(从匹配点)。如果没有找到该字符串,则返回 false。
php 判断字符串在另一个字符串中位置
$email='user@example.com'; //定义字符串
$result=strstr($email,'@'); //返回子字符串
echo $result;
/*
strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。
php 查找字符串中单词个数
*/
$str="hello world"; //定义字符串
$result=str_word_count($str); //查找单词个数
echo $result; //输出的结果
echo "<br>";
$result=str_word_count($str,1); //返回数组
print_r($result); //输出结果数组
php 把查询字符串解析到变量中
parse_str() 函数把查询字符串解析到变量中。
语法
parse_str(string,array)
注释:如果未设置 array 参数,由该函数设置的变量将覆盖已由同名变量。
php字符比较函数similar_text strnatcmp strcasecmp
similar_text() 函数计算两个字符串的匹配字符的数目。
该函数也可以计算两个字符串的相似度(以百分比计)。
php中实用的文件上传类
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 convert_uuencode() 与 convert_uuencode 函数
convert_uudecode() 函数对 uuencode 编码的字符串进行解码。
语法
convert_uudecode(string)
*/
$str=",2&5l;&/@=v]r;&0a `"; //定义uuencode编码字符串
$result=convert_uudecode($str); //解码
echo $result; //输出结果数据,hello world!
php printf函数格式化详细说明(1/2)
语法
printf(format,arg1,arg2,arg++)参数 描述
format 必需。规定字符串以及如何格式化其中的变量。
arg1 必需。规定插到格式化字符串中第一个 % 符号处的参数。
arg2 可选。规定插到格式化字符串中第二个 % 符号处的参数。
arg++ 可选。规定插到格式化字符串中第三、四等等 % 符号处的参数。
php常用的数组排序函数实例
/*
arsort(array,sorttype)
arsort() 函数对数组进行逆向排序并保持索引关系。主要用于对那些单元顺序很重要的结合数组进行排序。
可选的第二个参数包含了附加的排序标识。