D
D
devil's jackal2020-03-03 22:09:18
PHP
devil's jackal, 2020-03-03 22:09:18

How to get the registration date of a VK user?

I made a simple script to check if a page is alive for at least five days:

$text = file_get_contents("http://vk.com./foaf.php?id=1488");
preg_match('|<ya:created dc:date="(.*?)T|si', $text, $arr);
    $d = date("Y-m-d", mktime(0, 0, 0, date('m'), date('d') - 5, date('Y')));
    print "Created: {$arr[1]} | Compare date: {$d}";
    if ($d > $arr[1]) {echo ' | page is ok.';} else {echo ' | error, page is new.';}


But the catch is that everything works, except for getting the registration date: I tried to get it all through SimpleXML, and through file_get_contents, but in response, only emptiness. The script itself is correct.
Can you help the stupid people?
-
In fact, this is a working option. Just read the comments below the question.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nokimaro, 2020-03-03
@Deathfinite

<?php
$text = file_get_contents("https://vk.com/foaf.php?id=1488");
preg_match('|ya:created dc:date="(.*?)"|si', $text, $arr);

$time_create = strtotime($arr[1]);
$time_current = time();

$check_time = 5/*дн.*/*86400; //5 полных суток

echo "Created: ".date("d-m-Y H:i:s", $time_create)."\n";
echo "Compare date: ".date("d-m-Y H:i:s", $time_current)."\n";

if(abs($time_current-$time_create) >= $check_time)
{
    echo "С момента регистрации прошло больше 5 дн."."\n";
}
else
{
    echo "С момента регистрации прошло меньше 5 дн."."\n";
}

work result
Created: 02-12-2006 13:10:20
Compare date: 03-03-2020 22:49:32
More than 5 days have passed since registration.

S
Sergey Sokolov, 2020-03-04
@sergiks

$date_str = simplexml_load_file('https://vk.com/foaf.php?id=1')
  ->xpath('//ya:created/@dc:date')[0];
// 2006-09-23T20:27:12+03:00

$now = new DateTime();
$then = new DateTime($date_str);
$interval = $then->diff($now);
echo $interval->format('%a дней'); 
// 4910 дней

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question