V
V
Valery Zinchenko2016-07-08 15:22:56
PHP
Valery Zinchenko, 2016-07-08 15:22:56

How to break vk url?

I need to know how to break the VK link https://vk.com/wall-1234567_890 into post_id and owner_id variables.
I tried something myself, it doesn’t work, I tried it like parse_url , but even my hosting didn’t understand how this function works, it’s not like you, I don’t even have a brain. In general, I either don’t know how to work with this function, or I don’t know anything at all. Can you help?
Decision:

<?

preg_match('/wall(\d+)_(\d+)/', 'wall-1234567_890', $matches);
list(, $post_id, $owner_id) = $matches;

var_dump($post_id, $owner_id);

?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2016-07-08
@officialmuse

There are a lot of options. Simplest:

php > preg_match('/wall-(\d+)_(\d+)/', 'https://vk.com/wall-1234567_890', $matches);
php > var_dump($matches);
array(3) {
  [0]=>
  string(16) "wall-1234567_890"
  [1]=>
  string(7) "1234567"
  [2]=>
  string(3) "890"
}

// EDIT
With all due respect, it's absurd to ask that in an addendum.)
// EDIT 2 for the little ones
<?php

preg_match('/wall-(\d+)_(\d+)/', 'wall-1234567_890', $matches);
list(, $post_id, $owner_id) = $matches;

var_dump($post_id, $owner_id);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question