Change language

PHP Preg_filter () function

|
Syntax:
preg_filter ($pattern, $replacement, $subject, $limit, $count) 
Parameters: This function takes the five parameters mentioned above and described below.
  • $pattern:this parameter contains the string element to search for, which can be a string or an array of strings.
  • $replace:Required parameter that specifies a string or array with strings to replace.
  • $subject:string or array with strings to find and replace.
  • $limit:This parameter specifies the maximum possible replacements for each pattern.
  • $count: this is an optional parameter that is used to fill with the number of replacements performed.
Return value:this function returns an array if the object parameter is an array, or a string otherwise .Below the program illustrates the function preg_filter() in PHP:
Program 1:  
// PHP illustration program
// preg_filter function $string = ’November 01, 2018’ ; $pattern = ’/ (w + ) (d +), (d +) / i’ ; $replacement = ’${1 } 02, $3’ ;  
// print the result echo preg_filter ( $pattern , $replacement , $string ); ?>
Exit:
November 02, 2018 
Program 2:  
// PHP program to illustrate the preg_filter function $subject = array ( ’1’ , ’ GFG’ , ’2’ , ’Geeks’ , ’ 3’ , ’GCET’ , ’ Contribute’ , ’4’ ); $pattern = array ( ’/ d /’ , ’ / [az] / ’ , ’ / [1a] / ’ ); $replace = array ( ’X: $0’ , ’ Y: $0’ , ’Z: $0’ ) ; echo " Returned Array by preg_filter " ; print_r (preg_filter ( $pattern , $replace , $subject )); ?>
Exit:
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) 
Link: http://php.net/manual/en/function.preg-filter.php

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method