$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

  • one
    Oh, you again? - user6550


1 answer 1

I think we need to add one more group to the end for everything else, i.e. for all that that does not fall into [a-z0-9_], but are you sure that you correctly cut? % 2F is just a coded character, i.e. for the line photo67601378_301447204% 2Falbum67601378_00% 2Frev, you must run url_decode

 preg_replace('/^(https?:\/\/vk\.com\/)[a-z0-9\/]+\?z=([a-z0-9_])(.*)/','$1$2',$str);