YouTip LogoYouTip

Php Preg_Replace

# PHP preg_replace() Function [![Image 3: PHP Regular Expressions (PCRE)](#)PHP Regular Expressions (PCRE)](#) The preg_replace function performs a regular expression search and replace. ### Syntax mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] ) Searches subject for matches to pattern and replaces them with replacement. Parameter Explanation: * $pattern: The pattern to search for. It can be a string or an array of strings. * $replacement: The string or array of strings to replace with. * $subject: The string or array of strings to search and replace. * $limit: Optional. The maximum number of replacements for each pattern in each subject string. Default is -1 (no limit). * $count: Optional. The number of replacements performed. ### Return Value If subject is an array, preg_replace() returns an array, otherwise it returns a string. If a match is found, the modified subject is returned, otherwise the subject is returned unchanged. If an error occurs, NULL is returned. ### Examples ## Replace google with tutorial The execution result is as follows: tutorial 123,456 * * * ## Remove Whitespace Characters The execution result is as follows: tutorial * * * ## Using Array Index Based Search and Replace The execution result is as follows: The bear black slow jumped over the lazy dog. * * * ## Using the count Parameter The execution result is as follows: xp***to 3 [![Image 4: PHP Regular Expressions (PCRE)](#)PHP Regular Expressions (PCRE)](#)
← Docker Install RedisPhp Preg_Replace_Callback_Arra β†’