preg_filter用法
生活随笔
收集整理的這篇文章主要介紹了
preg_filter用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
preg_filter?—?執行一個正則表達式搜索和替換
preg_filter(
????mixed?$pattern,
????mixed?$replacement,
????mixed?$subject,
????int?$limit?= -1,
????int?&$count?= ?
):?mixed
preg_filter()等價于preg_replace()除了它僅僅返回(可能經過轉化)與目標匹配的結果.?
返回值
如果subject是一個數組,返回一個數組, 其他情況返回一個字符串。
如果沒有找到匹配或者發生了錯誤,當subject是數組 時返回一個空數組,其他情況返回null。
<?php $subject = array('1', 'a', '2', 'b', '3', 'A', 'B', '4'); $pattern = array('/\d/', '/[a-z]/', '/[1a]/'); $replace = array('A:$0', 'B:$0', 'C:$0'); echo "preg_filter returns\n"; print_r(preg_filter($pattern, $replace, $subject)); echo "preg_replace returns\n"; print_r(preg_replace($pattern, $replace, $subject)); ?>效果:
?
總結
以上是生活随笔為你收集整理的preg_filter用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu系统下安装php环境
- 下一篇: preg_grep用法