sandbox.onlinephpfunctions.com/code/2652fbd2c56fe0...$text = "any text site1.ru site2.com mysite.ru";
$excludeSites = [ "mysite.ru" ];
foreach( $excludeSites as $siteID => $siteName )
{
$text = str_replace( $siteName, "{{SITE_ID_" . $siteID . "}}", $text );
}
$newText = preg_replace('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', '***', $text);
foreach( $excludeSites as $siteID => $siteName )
{
$newText = str_replace( "{{SITE_ID_" . $siteID . "}}", $siteName, $newText );
}
echo $newText;
Результат работы кода: any text *** *** mysite.ru
Тут сайты для исключения замены:
$excludeSites = [ "mysite.ru" ];//[ "mysite.ru", "mysite2.ru" ]