正在读取数据,页面载入中,请稍后...

PHP中使用正则表达式来检测字符中是否含有大写字母

使用preg_match()函数配合正则表达式来检测是否含有大写字母

PHP中使用正则表达式来检测字符中是否含有大写字母 - PHP学习之路

preg_match 函数用于执行一个正则表达式pattern匹配,会返回 pattern 的匹配次数(0或1)。0代表没有匹配,1代表有匹配。

用到的正则为:/[A-Z]/,用于查找大写字母

<?php
function is_bigstr($str)
{
    if(preg_match('/[A-Z]/', $str)){
    	echo '有大写字母!<br>';
	}else{
	    echo '没有大写字母!<br>';
	}
}
is_bigstr('hello');
is_bigstr('Hello');
?>

本文结束