美文网首页
9.3.3 字符串的匹配与查找之(preg_match_all与

9.3.3 字符串的匹配与查找之(preg_match_all与

作者: 曹渊说创业 | 来源:发表于2016-12-19 08:39 被阅读109次

9.3.3 字符串的匹配与查找之(preg_match_all与preg_grep)

test.php

<?php
/*  $reg = '/(https?|ftps?):\/\/(www|mail|bbs|ftp)\.(.*?)\.(net|com|org|cn)([\w-\.\/\=\?\&\%]*)?/';
    $reg = '/\w+([+-.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* /i';

 *  分割、匹配、查找、替换
 *
 *  1. 字符串处理函数 (处理快, 但有一些做不到)
 *
 *  2. 正则表达式函数  (功能强大,但效率要低)
 *
 *
 *  注意:如果可以直接使用字符串处理函数处理的字符串,就不要使用正则处理
 *
 *
 *  
 * 匹配查找:
 *
 *  strstr  strpos substr
 *
 *
 * 正则匹配查找
 *
 *  preg_match()   preg_match_all()   preg_grep();
 *
 */
    header("Content-Type:text/html;charset=utf-8");

    

    $arr = array("abcd1", "he llo2", "world", "ni hao");


    $content=preg_grep('/\s/', $arr);

    print_r($content);

相关文章

网友评论

      本文标题:9.3.3 字符串的匹配与查找之(preg_match_all与

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