美文网首页
PHP 字符串截取()[]{} 中内容

PHP 字符串截取()[]{} 中内容

作者: 中華田園雞 | 来源:发表于2017-12-27 14:20 被阅读0次
$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]; 
}

相关文章

网友评论

      本文标题:PHP 字符串截取()[]{} 中内容

      本文链接:https://www.haomeiwen.com/subject/morugxtx.html