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 PHP array_filter() Function This built-in function in PHP is used to filter the elements of an array using a user-defined function which is also called a callback function. The array_filter() function iterates over each value in the array, passing them to the user-defined function or the callback function. If the callback func 2 min read PHP | DsMap filter() Function The Ds\Map::filter() function is an inbuilt function in PHP which is used to create a new map using the filter function. Syntax: public Ds\Map::filter( $callback ) Parameters: It contains a single parameter $callback which is an optional parameter and it returns True if the value should be included, 2 min read PHP | DsSet filter() Function The Ds\Set::filter() function is an inbuilt function in PHP which is used to create new set using filter function. Syntax: Ds\Set public Ds\Set::filter( $callback ) Parameters: This function accepts single parameter $callback which is optional and it returns True if the value should be included, Fal 1 min read PHP prev() Function The prev() function is an inbuilt function in PHP. It is used to return the immediate previous element from an array of the element which is currently pointed by the internal pointer. We have already discussed current() function in PHP. The current() function is used to return the value of the eleme 2 min read PHP | Imagick filter() Function The Imagick::filter() function is an inbuilt function in PHP which is used to apply custom convolution kernel to the image. A kernel, convolution matrix, or mask is a small matrix. It is used for blur, sharpen, embossing, edge detection, and many more. Syntax: bool Imagick::filter( $ImagickKernel, $ 1 min read Like