In this pattern:
$pattern = '/(\s*)@(if|foreach)(\s*\(.*\))/';
How can I replace every # with $ on (\s*(.*))
This will be used afterwards:
preg_replace($pattern, '$1<?php $2$3: ?>', $value);
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.
You are looking for preg_replace_callback.
There you can define an anonymous function that returns the replacement, where you would be able to perform your additional task on group 3 and then build the replacement as you need.
From the example in the second link
You can see that you can access the group 3 like this:
$match[3]