At the minute I have:
$Text = preg_replace("/\[code\](.*?)\[\/code\]/s", "<mytag>\\1</mytag>", $Text);
How can I escape the backreference using htmlentities()?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As seen in the
preg_replace_callback()documentation, you can also create the callback function inline, viacreate_function()or as of PHP 5.3.0 even use an anonymous function.The generic approach however would be along the lines of this:
Also I guess (I have not measured) that this regex could be a bit faster, because the reluctant quantifier would not be invoked more often than necessary: