PHP POSIX扩展正则表达式函数

来源:互联网 发布:三菱plc3u编程手册 编辑:程序博客网 时间:2024/04/27 05:53

1.erge()函数和eregi()函数

ereg函数()

bool ereg(string pattern,string string [,array regs])

在字符串string中匹配表达式pattern,成功返回true,失败返回false,如果有第三个参数regs,则将成功的表达式放到regs数组里

$email_id = "admin@tutorialspoint.com";
$retval = ereg("(\.)(com$)",$email_id);
if($retval==true){
echo "Found a .com<br>";
}
else{
echo "Could not found a .com<br>";
}
$retval = ereg("(\.)(com$)",$email_id,$regs);
if($retval==true){
echo "Found a .com and reg = ".$regs[0];
}
else{
echo "Could not found a .com";
}

2.ereg_replace()函数

string  ereg_replace(string pattern,string replacement,string string)

函数功能:在字符串string 中匹配表达式pattern,如匹配成功,则用replacemnet来替代匹配字符串,本函数不区分大小写。

$ereg = 'tm';
$str = 'hello,tm,Tm,tM';
$rep_str = eregi_replace($ereg,'TM',$str);
echo $rep_str;

3.split()函数

array split(string pattern,string string [,])

函数功能:使用表达式pattern来分割字符串string,如果有参数limit 那么数组最多有limit个元素,剩余部分都写到最后一个数组元素中。

$ereg='is';
$str='This is a register book';
$arr_str=spliti($ereg,$str);
var_dump($arr_str);


原创粉丝点击