<span id="dzrfh"></span>

    <noframes id="dzrfh"><form id="dzrfh"></form>
    <noframes id="dzrfh">
        <form id="dzrfh"><th id="dzrfh"><th id="dzrfh"></th></th></form>

            全國熱線:0536-8800925
            新聞動態

            PHP正則表達式匹配 preg_match函數 與 preg_match_all 函數區別

            一:preg_match函數
            定義:preg_match() 函數用于進行正則表達式匹配,成功返回 1 ,否則返回 0 。

            語法

            int preg_match( string pattern, string subject [, array matches ] )
            參數 描述
            pattern 必需。正則表達式
            subject 需要匹配檢索的對象
            matches 可選。存儲匹配結果的數組, $matches[0] 將包含與整個模式匹配的文本,$matches[1] 將包含與第一個捕獲的括號中的子模式所匹配的文本,以此類推
             

            二:ptrg_match_all()

            定義和用法

            preg_match_all() 函數用于進行正則表達式全局匹配,成功返回整個模式匹配的次數(可能為零),如果出錯返回 FALSE 。

            語法

            int preg_match_all( string pattern, string subject, array matches [, int flags ] ) 
            參數 描述
            pattern 必需。正則表達式
            subject 必需。規定要插入的字符串。
            matches 必需。存儲匹配結果的數組
            flags 可選。指定匹配結果放入 matches 中的順序,可供選擇的標記有:
            • PREG_PATTERN_ORDER:默認,對結果排序使 $matches[0] 為全部模式匹配的數組,$matches[1] 為第一個括號中的子模式所匹配的字符串組成的數組,以此類推
            • PREG_SET_ORDER:對結果排序使 $matches[0] 為第一組匹配項的數組,$matches[1] 為第二組匹配項的數組,以此類推
            • PREG_OFFSET_CAPTURE:如果設定本標記,對每個出現的匹配結果也同時返回其附屬的字符串偏移量
            在線咨詢
            Tel

            0536-8800925

            關注我們微信