欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

php正則匹配類(lèi)

  1. 代碼:
    /**
    * @desc:正則匹配類(lèi)
    * @author [Lee] <[<complet@163.com>]>
    * @method
    * 1、geturl         獲取所有超鏈接
    * 2、getimg         獲取所有圖片
    * 3、getaudio           獲取所有音頻文件
    * 4、getvideo           獲取所有視頻文件
    * 5、getparagraph       獲取所有段落
    * 6、getuser            獲取自定義內(nèi)容         preg 自定義正則,如:/<h2>(.*)<h2>/Ui
    */
    class match{
    private $content = '';
    /*
     @desc:構(gòu)造方法,初始化待匹配文本
     */
    public function __construct($content){
        $this->content = $content;
    }
    /*
     @desc:獲取所有超鏈接
     @return:所有匹配的超鏈接
     */
    public function geturl(){
        $content = $this->content;
        $preg = '/<[a|A].*?href=[\'\"]{0,1}([^>\'\"\ ]*).*?>/i';
        $bool = preg_match_all($preg,$content,$res);
        $urls = array();
        if($bool){
            $urls = $res[1];
        }
        return array_unique($urls);
    }
    /*
     @desc:獲取所有圖片
     @return:所有匹配的圖片
     */
    public function getimg(){
        $content = $this->content;
        $preg="/(src)=(\\\?)([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png|svg))\\2\\3/i";
        $bool = preg_match_all($preg,$content,$res);
        $imgs = array();
        if($bool){
            $imgs = $res[4];
        }
        return array_unique($imgs);
    }
    /*
     @desc:獲取所有音頻文件
     @return:所有匹配的音頻文件
     */
    public function getaudio(){
        $content = $this->content;
        $preg="/(src)=(\\\?)([\"|']?)([^ \"'>]+\.(mp3|wav|wma|ogg|ape|acc))\\2\\3/i";
        $bool = preg_match_all($preg,$content,$res);
        $audios = array();
        if($bool){
            $audios = $res[4];
        }
        return array_unique($audios);
    }
    /*
     @desc:獲取所有視頻文件
     @return:所有匹配的視頻文件
     */
    public function getvideo(){
        $content = $this->content;
        $preg="/(src)=(\\\?)([\"|']?)([^ \"'>]+\.(swf|flv|mp4|rmvb|avi|mpeg|ra|ram|mov|wmv)((\?[^ \"'>]+)?))\\2\\3/i";
        $bool = preg_match_all($preg,$content,$res);
        $videos = array();
        if($bool){
            $videos = $res[4];
        }
        return array_unique($videos);
    }
    /*
     @desc:獲取所有段落文本
     @return:所有匹配的段落文本
     */
    public function getparagraph(){
        $content = $this->content;
        $preg="/<p>(.*)<\/p>/Ui";
        $bool = preg_match_all($preg,$content,$res);
        $paragraphs = array();
        if($bool){
            $paragraphs = $res[1];
        }
        return array_unique($paragraphs);
    }
    /*
     @desc:獲取所有自定義內(nèi)容
     @return:所有匹配的自定義內(nèi)容
     */
    public function getuser($preg){
        $content = $this->content;
        $bool = preg_match_all($preg,$content,$res);
        $users = array();
        if($bool){
            $users = $res[1];
        }
        return array_unique($users);
    }
    }
  2. 測(cè)試:
    $match = new match($str);
    $ret = $match->getimg();
    var_dump($ret);
  3. 輸出:
    array(7) {
    [0]=>
    string(61) "https://assets-cdn.github.com/images/search-shortcut-hint.svg"
    [1]=>
    string(69) "https://assets-cdn.github.com/images/spinners/octocat-spinner-128.gif"
    [2]=>
    string(75) "https://assets-cdn.github.com/images/spinners/octocat-spinner-32-EAF2F5.gif"
    [3]=>
    string(68) "https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif"
    [14]=>
    string(45) "https://badges.gitter.im/walkor/Workerman.svg"
    [15]=>
    string(48) "/upload/otherpic47/106945.jpg"
    [16]=>
    string(42) "http://donate.workerman.net/img/donate.png"
    }

當(dāng)前名稱(chēng):php正則匹配類(lèi)
文章出自:http://chinadenli.net/article4/ihjsie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、服務(wù)器托管、網(wǎng)站收錄、網(wǎng)站導(dǎo)航、外貿(mào)建站、動(dòng)態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名
日韩国产亚洲欧美另类| 国产一区二区三区免费福利| 成人午夜爽爽爽免费视频| 午夜福利视频日本一区| 粗暴蹂躏中文一区二区三区| 91日韩在线观看你懂的| 亚洲天堂男人在线观看| 亚洲精品国男人在线视频| 日韩精品人妻少妇一区二区| 久久国产成人精品国产成人亚洲| 亚洲欧美日韩国产自拍| 伊人色综合久久伊人婷婷| 成在线人免费视频一区二区| 99视频精品免费视频播放| 精品一区二区三区不卡少妇av| 日韩欧美二区中文字幕| 国产精品日本女优在线观看| 国产一区欧美一区日本道| 亚洲二区欧美一区二区| 最近日韩在线免费黄片| 国产成人精品午夜福利| 高清不卡视频在线观看| 五月天婷亚洲天婷综合网| 亚洲男人的天堂久久a| 亚洲av专区在线观看| 国产成人精品国内自产拍| 国产av大片一区二区三区| 亚洲国产欧美久久精品| 亚洲精品av少妇在线观看| 扒开腿狂躁女人爽出白浆av | 亚洲国产精品一区二区| 丰满人妻一二三区av| 隔壁的日本人妻中文字幕版| 欧美日韩无卡一区二区| 最新日韩精品一推荐日韩精品 | 亚洲中文字幕在线观看黑人| 日韩在线免费看中文字幕| 国产传媒精品视频一区| 精品熟女少妇一区二区三区| 91久久精品中文内射| 亚洲国产一区精品一区二区三区色|