php preg_replace everything in between specific html comment tags
php, preg-replace, regex
Solution
Thanks @mlwacosmos - Using the link you provided.
Achieved with:
$startPoint = '<!-- START IF USER_ID -->';
$endPoint = '<!-- END IF USER_ID -->';
$result = preg_replace('#('.preg_quote($startPoint).')(.*)('.preg_quote($endPoint).')#siU', '', $html);
Problem
I've checked other answers but can't seem to do the following. Please help someone :) I want to remove everything in between and including specific html comments HTML: ``` Some HTML that must stay <!-- START IF USER_ID --> some html that must go <!-- END IF USER_ID --> Some more HTML that's gotta stay <!-- START IF USER_ID --> this also needs to go <!-- END IF USER_ID --> ``` So everything in between `<!-- START IF USER_ID -->` and `<!-- END IF USER_ID -->` and the comments itself needs to go My preg_replace pattern (which is obviously wrong): ``` "/<!-- START IF USER_ID -->.*?<!-- END IF USER_ID -->/" ``` Result should be ``` Some HTML that must stay Some more HTML that's gotta stay ``` Thanks for checking and for the answers in advance :)