twix007
@twix007

Как сделать preg_match для VK и Instagram?

Здравствуйте уважаемые!
Как переделать код:
// Convert user input social URLs to username values
        $facebookUrl = $user->facebook;
        preg_match("/https?:\/\/(www\.)?facebook\.com\/([^\/]*)/", $facebookUrl, $matches);
        if ($matches){
            $user->facebook = $matches[2];
        }
        $twitterUrl = $user->twitter;
        preg_match("/https?:\/\/(www\.)?twitter\.com\/(#!\/)?@?([^\/]*)/", $twitterUrl, $matches);
        if ($matches){
            $user->twitter = $matches[3];
        }
        $linkedinUrl = $user->linkedin;
        preg_match("/https?:\/\/(www\.)?linkedin\.com\/in\/([^\/]*)/", $linkedinUrl, $matches);
        if ($matches){
            $user->linkedin = $matches[2];
        }
        $googleplusUrl = $user->googleplus;
        preg_match("/https?:\/\/plus\.google\.com\/([^\/]*)/", $googleplusUrl, $matches);
        if ($matches){
            $user->googleplus = $matches[1];
        }
        $pinterestUrl = $user->pinterest;
        preg_match("/https?:\/\/(www\.)?pinterest\.com\/([^\/]*)/", $pinterestUrl, $matches);
        if ($matches){
            $user->pinterest = $matches[2];
        }


и добавить
https://vk.com/username и https://vk.com/id1
https://instagram.com/username

Код оставляет только username или id
  • Вопрос задан
  • 553 просмотра
Решения вопроса 1
Stalker_RED
@Stalker_RED
/https?:\/\/(www\.)?instagram\.com\/([^\/].+)/ # instagram username
/https?:\/\/(www\.)?vk\.com\/([^\/].+)/ # vk username
/https?:\/\/(www\.)?vk\.com\/id([^\/]\d+)/ # vk id123
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
twix007
@twix007 Автор вопроса
Можно ещё допилить попросить... (ничего не получается у самого)
https://plus.google.com/u/0/+Username + https://plus.google.com/u/2/Username/posts
https?:\/\/plus\.google\.com\/([^\/]*)
#хватает только "u"

https?:\/\/(www\.)?instagram\.com\/([^\/].+)
#instagram режет: "username/" - как убрать в конце "/" ?

Нурлан Касымов Stalker_RED
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы