PHP preg_filter():执行一个正则表达式的搜索和替换
PHP preg_filter() 函数也用于执行一个正则表达式的搜索和替换,等价于我们前面介绍的《preg_replace() 函数》,不同的是 preg_filter() 函数只返回匹配成功的结果,而 preg_replace() 返回所有结果,不管是否匹配成功。
关于 preg_filter() 的工作原理和参数说明请参考 preg_replace() 函数。
preg_filter() 函数的使用示例如下:
			
			
关于 preg_filter() 的工作原理和参数说明请参考 preg_replace() 函数。
preg_filter() 函数的使用示例如下:
<?php
    echo "<pre>";
    $arr1 = array(
        'https://www.xinbaoku.com/php/',
        'https://www.xinbaoku.com/java/',
        'https://www.xinbaoku.com/python/',
        'http://www.google.com/cn/',
        'http://cn.bing.com/',
    );
    $pattern = array('/c\./','/biancheng/');
    $replacement = array('www.','baidu');
    print_r( preg_replace($pattern, $replacement, $arr1) );
    print_r( preg_filter($pattern, $replacement, $arr1) );
?>
执行以上程序的结果如下:
	Array
	(
	    [0] => http://www.baidu.net/php/
	    [1] => http://www.baidu.net/java/
	    [2] => http://www.baidu.net/python/
	    [3] => http://www.google.com/cn/
	    [4] => http://cn.bing.com/
	)
	Array
	(
	    [0] => http://www.baidu.net/php/
	    [1] => http://www.baidu.net/java/
	    [2] => http://www.baidu.net/python/
	)
所有教程
- C语言入门
- C语言编译器
- C语言项目案例
- 数据结构
- C++
- STL
- C++11
- socket
- GCC
- GDB
- Makefile
- OpenCV
- Qt教程
- Unity 3D
- UE4
- 游戏引擎
- Python
- Python并发编程
- TensorFlow
- Django
- NumPy
- Linux
- Shell
- Java教程
- 设计模式
- Java Swing
- Servlet
- JSP教程
- Struts2
- Maven
- Spring
- Spring MVC
- Spring Boot
- Spring Cloud
- Hibernate
- Mybatis
- MySQL教程
- MySQL函数
- NoSQL
- Redis
- MongoDB
- HBase
- Go语言
- C#
- MATLAB
- JavaScript
- Bootstrap
- HTML
- CSS教程
- PHP
- 汇编语言
- TCP/IP
- vi命令
- Android教程
- 区块链
- Docker
- 大数据
- 云计算
