Please consider the following paragraph...
{{if|service_name=Service}}
Hello this is the Service text
{{endif}}
This is the format that I allow my users to place custom conditional variables inside contract text. This means that if the service matches "Service", the text will show. I achieve this replacement functionality with the following....
$text = preg_replace("/{{if\|service_name=$service}}\s*(.*?)\R{{endif}}/s", "$1", $text);
This works great, right up until CKeditor is used on the contract text field, and my clients new lines are wrapped in <p> tags.
So the above works, but this does not..,
<p>{{if|service_name=Service}}</p>
<p>Hello this is the Service text</p>
<p>{{endif}}</p>
I have placed an example here... https://www.phpliveregex.com/p/pEE
Can anyone shed some light on my issue?
\Rsince there is no line break between<p>and{{endif}}3) Do not useUmodifier that switches greediness. See regex101.com/r/kKt2M6/1<p>tags when matching, you will have to remove them with somestr_replace(['<p>', '</p>'], '', $res)or similar option (orstrip_tags) after extraction.