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

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically