preg_match_all('/(\s|^)(\[.*?\]|.*?)(?=(\s|$))/', 'Купить !автомобиль [недорого москва] [новый или !бу]', $m);
preg_replace(
'/(\<p[^\>]*\>)(.*)\<\/p\>/miuU',
'$1<i>$2</i></p>',
$text
);
preg_replace_callback(
'/(\<p[^\>]*\>)(.*)\<\/p\>/miuU',
function( $match ) {
return $match[1] . '<i>' . $match[2] . '</i>' . '</p>';
},
$text
);