PHP | preg_filter() Function Last Updated : 22 Oct, 2018 Comments Improve Suggest changes Like Article Like Report The preg_filter() function is an inbuilt function in PHP which is used to perform a regular expression search and replace the text. Syntax: preg_filter( $pattern, $replacement, $subject, $limit, $count ) Parameters: This function accepts five parameters as mention above and describe below. $pattern: This parameter contains an string element which is search for and it can be a string or array of string. $replacement: It is mandatory parameter which specifies the string or an array with strings to replace. $subject: The string or an array with strings to search and replace. $limit: This parameter specifies the maximum possible replacements for each pattern. $count: It is optional parameter which is used to fill with the number of replacements done. Return Value: This function returns an array if the subject parameter is an array, or a string otherwise. Below program illustrates the preg_filter() function in PHP: Program 1: php <?php // PHP program to illustrate // preg_filter function $string = 'November 01, 2018'; $pattern = '/(\w+) (\d+), (\d+)/i'; $replacement = '${1} 02, $3'; // print result echo preg_filter($pattern, $replacement, $string); ?> Output: November 02, 2018 Program 2 : php <?php // PHP program to illustrate preg_filter function $subject = array('1', 'GFG', '2', 'Geeks', '3', 'GCET', 'Contribute', '4'); $pattern = array('/\d/', '/[a-z]/', '/[1a]/'); $replace = array('X:$0', 'Y:$0', 'Z:$0'); echo "Returned Array by preg_filter"; print_r(preg_filter($pattern, $replace, $subject)); ?> Output: Returned Array by preg_filterArray ( [0] => X:Z:1 [2] => X:2 [3] => GY:eY:eY:kY:s [4] => X:3 [6] => CY:oY:nY:tY:rY:iY:bY:uY:tY:e [7] => X:4 ) Reference: http://php.net/manual/en/function.preg-filter.php Comment More infoAdvertise with us Next Article PHP | preg_filter() Function R R_Raj Follow Improve Article Tags : Misc Web Technologies PHP PHP-function Practice Tags : Misc Similar Reads PHP | filter_id() Function The filter_id() function is an inbuilt function in PHP which returns the filter ID of a specified filter name. It is used to get the filter id of the particular filter in PHP by using filter_id function by giving the name of the filter as input and get the associated id to it. Syntax: int filter_id( 2 min read PHP | filter_has_var() function The filter_has_var() function is an inbuilt function in PHP which is used to check whether the variable available or not especially it checks if a variable of a specified input type exist or not. It returns True on success or False on failure. Syntax: bool filter_has_var( $type, $variable_name ) Par 2 min read PHP | stream_get_filters() Function The stream_get_filters() function is an inbuilt function in PHP which is used to get the list of registered stream filters. Syntax: array stream_get_filters( void ) Parameters: This function does not accept any parameter. Return Value: This function returns an array containing the name of all availa 1 min read PHP | filter_list() Function The filter_list() function is an inbuilt function in PHP which is used to returns the list of all supported filters. Syntax: array filter_list( void ) Parameters: This function does not accepts any parameters. Return Values: It returns an array containing all names of supported filters. If it return 2 min read PHP | filter_input() Function The filter_input() is an inbuilt function in PHP which is used to get the specific external variable by name and filter it. This function is used to validate variables from insecure sources, such as user input from form. This function is very much useful to prevent some potential security threat lik 2 min read Like