- preg\_replace( \$pattern,\$replacement,\$subject),preg\_filter ( \$pattern,\$replacement,\$subject); preg\_replace 和preg\_filter 将匹配到的数值进行替换,可以使用数组替换;\ $replacement 将匹配到的值替换为这个变量中存放的值; \$pattern正则表达式; \$subject返回结果;
Difference:
functionshow($var = null){if(empty($var)){ echo'null'; }elseif(is_array($var)||is_object($var)){ echo'
'; Print_r ($var);Echo''; }Else{Echo$var; }}//preg_replace,preg_filter//$pattern = '/[0-9]/'; //String$pattern=Array('/[0123]/','/[456]/','/[789]/');//Array//$subject = ' y1jp78yn16ww55j9 ';//is a string, using $pattern and $replacement to make a match substitution$subject=Array(' y ',' 1jp78 ',' yn ',' 16WW ',' 55j9 ');//$subject string is arbitrarily split into several segments, placed in the $subject array, each of the values in the group is replaced by a match//$replacement = ' mu goddess ';//the variable to be replaced when $subject matches the result$replacement=Array(' Mu ',' Woman ',' God ');$str 1= Preg_replace ($pattern,$replacement,$subject);//Keep all strings$str 2= Preg_filter ($pattern,$replacement,$subject);//Only preserves strings that have been replacedShow$str 1);Echo'
'; Show ($str 2);
Results:
Conclusion:
preg\_replace在数组匹配中会输出未发生匹配的字段;preg\_filter 在数组匹配中不会输出未发生匹配的字段;
- Preg_grep ($pattern,array $input)
The function is similar to Preg_filter, only matches does not replace and only returns the string or array that matches, can act as a filter, filter out the string or array that preg_filter not replace.
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ (''). Text (i)); }; $numbering. FadeIn (1700); }); }); The above describes the regular expression of PHP replace,filter,grep, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.