php 正则

2024-02-15 17:14:00 举报文章
//by www.qzphp.cn
$str="你好<我>(爱)[北京]{天安门}";
echo f1($str); //返回你好
echo f2($str); //返回我
echo f3($str); //返回爱
echo f4($str); //返回北京
echo f5($str); //返回天安门
function f1($str)
{
$result = array();
preg_match_all("/^(.*)(?:<)/i",$str, $result);
return $result[1][0];
}
 
function f2($str)
{
$result = array();
preg_match_all("/(?:<)(.*)(?:>)/i",$str, $result);
return $result[1][0];
}
function f3($str)
{
$result = array();
preg_match_all("/(?:\()(.*)(?:\))/i",$str, $result);
return $result[1][0];
}
function f4($str)
{
$result = array();
preg_match_all("/(?:\[)(.*)(?:\])/i",$str, $result);
return $result[1][0];
}
function f5($str)
{
$result = array();
preg_match_all("/(?:\{)(.*)(?:\})/i",$str, $result);
return $result[1][0];
}
如果你认为本文可读性较差,内容错误,或者文章排版错乱,请点击举报文章按钮,我们会立即处理!