performing multiple preg_replace with different search & replace each time
preg_replace
can take an array just like str_replace
$string = 'I have a match1 and a match3, and here\'s a match2';
$find = ['/match1/', '/match2/'];
$replace = ['foo', 'bar'];
$result = preg_replace($find, $replace, $string);
You can also use T-Regx library
<?php
$stylesheet = file_get_contents('temp/'.$user.'/css/mobile.css');
$cssTag = 'bodybg';
$stylesheet = pattern("(/\*" . $cssTag . "\*/).*?(/\*/" . $cssTag . "\*/)", 'i')
->replace($stylesheet)
->all()
->by()
->map([
'searchforme' => 'replacewithme',
'searchforme1' => 'replacewithme2',
'searchforme1' => 'replacewithme2',
]);
You don't need delimiters /
, because T-Regx automatically adds them