Artykuły na każdy temat
[PHP] Wyciąganie linków z archiwum WTW
<?php
set_time_limit(0);
header('Content-Type: text/plain; charset=utf-8');
// First things first
$path = 'path_to\.archive\database.sq3';
// Alias for SQLite
function regex($pattern, $subject)
{
return preg_match('#'.$pattern.'#', $subject) === 1;
}
$db = new sqlite3($path);
$db -> createfunction('regexp', 'regex', 2);
$result = $db -> query('SELECT entry_text FROM wtw_chat_data WHERE contact_id = 666 AND entry_text REGEXP "https?|s?ftp://"');
while($row = $result -> fetcharray(SQLITE3_NUM))
{
preg_match_all('#(?:https?|s?ftp)://[^\s]*#', $row[0], $matches);
if(count($matches[0]) > 0)
{
foreach($matches[0] as $link)
{
$links[] = $link;
}
}
}
if(count($links) > 0)
{
$links = array_unique($links);
foreach($links as $link)
{
// echo ++$h.' - ';
echo $link.PHP_EOL;
}
file_put_contents('./links.txt', implode(PHP_EOL, $links));
// file_put_contents('./links.json', json_encode($links));
// file_put_contents('./links.serialized', serialize($links));
// CSV, etc.
}
?>
Komentarze
Dodaj komentarz