$pattern,$subject,$replacement都为数组时两者的区别在于filter只保留替换的数组值,而replace保留了整个数组的值
当$pattern和$replacement 都为数组时,数组内包含的数量要匹配
当$subject也为数组时
preg_replacement匹配时无论数组中的元素有没有匹配上都会输出;
preg_filter匹配时只会输出匹配上元素,而没有匹配上的上的则不会被输出
一目了然的结果
$pattern,$subject,$replacement都为数组时两者的区别在于filter只保留替换的数组值,而replace保留了整个数组的值
$patten和$replacement为对应数组时,$subject为字符串时,匹配结果一样
preg_replace 与preg_filter将$subject里的符合$patten的字符或数组替换成$replaceent相对应该的字符串数组
replace-filter
1.把字符串 "Hello world!" 中的字符 "world" 替换为 "Shanghai":
<?php
echo str_replace("world","Shanghai","Hello world!");
?>一一对应匹配替换。preg_replace有没有替换的 都会返回。preg_filter只返回有替换的。
当$pattern和$replacement 都为数组时,数组内包含的数量要匹配
当$subject也为数组时
preg_replacement匹配时无论数组中的元素有没有匹配上都会输出;
preg_filter匹配时只会输出匹配上元素,而没有匹配上的上的则不会被输出