D
D
Dim Boy2015-11-13 19:21:55
PHP
Dim Boy, 2015-11-13 19:21:55

How to make preg_match for VK and Instagram?

Hello dear!
How to change the code:

// 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\/(#!\/)[email protected]?([^\/]*)/", $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];
        }

and add
https://vk.com/username and https://vk.com/id1
https://instagram.com/username
The code leaves only username or id

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2015-11-13
@twix007

/https?:\/\/(www\.)?instagram\.com\/([^\/].+)/ # instagram username
/https?:\/\/(www\.)?vk\.com\/([^\/].+)/ # vk username
/https?:\/\/(www\.)?vk\.com\/id([^\/]\d+)/ # vk id123

D
Dim Boy, 2015-11-18
@twix007

You can still ask to finish it ... (nothing works for me)
https://plus.google.com/u/0/+Username + https://plus.google.com/u/2/Username/posts
https? :\/\/plus\.google\.com\/([^\/]*) #only
"u" is enough
https?:\/\/(www\.)?instagram\.com\/([^ \/].+)
#instagram cuts: "username/" - how to remove "/" at the end?
Nurlan Kasymov Stalker_RED

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question