Requirements: Add a request=xxx after all connections; This function is more flexible than preg_replace, and note that it replaces the contents of the entire regular expression. $content = ' <a href= ' http://www.jzread.com/aaa.php ' > Link 1</a><a href= ' http://www.jzread.com/aaa.php? id=111 "> Link 2</a>"; function Add_source ($matches) { if (Strpos ($matches [1], '? ')) { Return ' href= '. $matches [1]. ' &request=xxx "'; Note that here and below are the things that are outside the regular brackets: href=. } Else { Return ' href= '. $matches [1]. Request=xxx "'; } } $content = Preg_replace_callback ('/href=[' |) (.*?) ['|"] /', ' Add_source ', $content);
Example Two
This text is used for 2002 years, Now want to make it available for 2003 $text = "April Jesters day is 04/01/2002n"; $text. = "Last Christmas was 12/24/2001n";
callback function function Next_year ($matches) { Typically: $matches [0] is a complete match $matches [1] is a match for the child pattern in the first parenthesis So return $matches [1]. ($matches [2]+1); }
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.