- substr: documentation ( source)
- preg_replace_callback: documentation ( source)
<?php
$msg = 'grjqgbqgrqg0 38975893240- http://www.gg.pl/afa31f312u34b151j5b1598139189 1234 http://www.fb.com/14';
$adNr = preg_replace_callback('#http://[^\s]+#', function($ma) {
if (substr($ma[0], 0, 17) !== 'http://www.gg.pl/') {
return $ma[0];
}
}, $msg);
echo $adNr;