function parse_parliament_member($url, $name) { $file = file_get_contents($url); $match = "|frame name=oikea2 src=(.*?htm) |"; if (preg_match($match, $file, $tmp)) { $file = file_get_contents("http://www.eduskunta.fi" . $tmp[1]); } else { die("ERROR"); } sleep(0.1); // Get main table $match = "|<table.*?>(.*?)</table>|ism"; if (preg_match_all($match, $file, $tables)) { $match = "|<tr.*?>(.*?)</tr>|ism"; unset($rows); if (preg_match_all($match, $tables[1][0], $rows)) { unset($n); $n = parse_rows($rows[1]); $n['Url'] = $url; $n['Alkuperäinen nimi'] = $name; return $n; } } else { die("ERROR: Page has no kansanedustaja! {$url}\n"); } }
$image_id = $matches[1][$i]; $sep = $matches[2][$i]; $comment_id = $matches[3][$i]; $user = get_user_from_comment($db, $comment_id); $base = $row['comment']; if (!is_null($user)) { $new = str_replace(">>{$image_id}{$sep}{$comment_id}", "[url=site://post/view/{$image_id}#c{$comment_id}]@{$user}[/url]", $base); print "\n\n----\n{$row['id']}\n--\n{$base}\n--\n{$new}"; update_comment($db, $row['id'], $new); } } } } } function get_user_from_comment($db, $comment_id) { $stmt = $db->prepare("SELECT name FROM users WHERE id=(SELECT owner_id FROM comments WHERE id=?)"); $stmt->execute(array($comment_id)); $row = $stmt->fetch(); if ($row) { return $row[0]; } return null; } function update_comment($db, $comment_id, $text) { $stmt = $db->prepare("UPDATE comments SET comment=? WHERE id=?"); $stmt->execute(array($text, $comment_id)); } parse_rows(get_db());