$str = 'https://vk.com/id67601378?z=photo67601378_301447204%2Falbum67601378_00%2Frev'; $r = preg_replace('/^(https?:\/\/vk\.com\/)[a-z0-9\/]+\?z=([a-z0-9_])/','$1$2',$str); echo $r; https://vk.com/photo67601378_301447204%2Falbum67601378_00%2Frev
how to cut shnyaga after photo67601378_301447204