PHPPOSIX扩展正则表达式函数

xiaoxiao2021-02-28  111

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);

转载请注明原文地址: https://www.6miu.com/read-69453.html

最新回复(0)