首页 > Web开发 > 详细

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

时间:2018-12-27 12:53:50      阅读:229      评论:0      收藏: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]; 
}

链接:https://www.jianshu.com/p/1926b0e7dc65

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

原文:https://www.cnblogs.com/sgm4231/p/10184092.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!