![]() ![]() So the result of the preg_replace() function will be stored in the “$copy_date1” variable. In the below example, a variable “$copy_date1” is created with the value “Copyright 1998” and then the same variable is created with the preg_replace() function as a value. Examples to Implement preg_replace() function in PHPīelow are some examples mentioned: Example #1 Check out the example so that you will know in example 2 below. You can use $0 for using the matched text. If we are writing some complicating multi-part regexes. The third parameter can contain $n which is to insert the text matched as a part of the regex rule. The second parameter is the plain text whereas the 3 rd parameter is the string which is to work. Preg_replace() will take regex as it’s a parameter (first parameter) which is used to replace for each match with the 2 nd parameter. The other parameters may not be that important. Mainly it works by using the original string which is used when searching and the replacing string/strings. Preg_replace() function of PHP programming language works based on the parameters mentioned inside of it. ![]() Return value for the preg_replace() function: The preg_replace() function will return array only if the subect1 parameter is an array/string. This parameter’s variable’s value-filled with the number which indicates the number of replacements done in the original string.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |