Basic application of PHP regular expressions

高洛峰
Release: 2023-03-01 12:50:01
Original
962 people have browsed it

The code is as follows:

<?php 
//正则表达 式 
// ereg区分大小写 
if(ereg("([A-Z]{3,})", "AAA")){ 
echo "大写能匹配!<br>"; 
}else{ 
echo "no"; 
} 
if(ereg("([A-Z]{3,})", "aaa")){ 
echo "yes"; 
}else{ 
echo "小写不能匹配!<br>"; 
} 
// eregi不区分大小写 
if(eregi("([A-Z]{3,})","Aaaa")){ 
echo "大小写都可以匹配!"; 
} 
//返回匹配的值 
if(ereg("^(0[0-9]{2,3})-([0-9]{7,8})","0592-5337138",$regs)){ 
echo "返回值0下标为原串$regs[0]<br>"; 
echo "返回区号(即第一个匹配串)".$regs[1]."<br>"; 
echo("返回电话号码(即第二个匹配串)$regs[2]<br>"); 
} 
?>
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!