php使用正则表达式提取字符串中尖括号、小括号、中括号、大括号中的字符串
2015-12-20 00:31
816 查看
</pre><p>PHP使用正则表达式提取字符串中尖括号<>、小括号()、中括号[]、大括号{}中的字符示例,需要的朋友可以参考下</p><p></p><p><pre name="code" class="php">$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]; }
相关文章推荐
- Window2003 iis+mysql+php+zend环境配置
- 中奖概率算法(php 可用于刮刮卡,大转盘等抽奖算法)
- 不用也要知道的几种算法(PHP版本)
- 基于PHP代码实现中奖概率算法可用于刮刮卡、大转盘等抽奖算法
- 使用PHP如何实现高效安全的ftp服务器(一)
- php封装好的人民币数值转中文大写类
- PHP版本常用的排序算法汇总
- 【嘉兴东臣PHP】DOM与BOM
- 【嘉兴东臣PHP】BOM + DOM
- 【嘉兴东臣php】JS+DOM+BOM笔记
- 【嘉兴东臣php】JS BOM DOM周总结
- 【嘉兴东臣php】BOM DOM JS
- 【嘉兴东臣php】BOM+DOM+作用域周总结
- Windows下简单搭建php开发环境
- php 冒泡排序 快速排序
- 安装交叉编译环境,minicom,tftp,nfs,partitionmanager
- ubuntu tftp
- PHP导出excel表格
- php实现验证码
- 利用PHP执行SQL文件,将SQL文件导入到数据库