Source code file content
subversion / 2c.lt / AddTitle.php
Size: 825 bytes, 1 line
<?php
function getMetaTitle($content){
$pattern = "|<[\s]*title[\s]*>([^<]+)<[\s]*/[\s]*title[\s]*>|Ui";
if(preg_match($pattern, $content, $match))
return $match[1];
else
return "";
}
require ("a/conf.php");
$UrlUzklausa="SELECT id, url from urls order by id desc limit 10";
$Rez=mysql_query($UrlUzklausa);
;
while ($row=mysql_fetch_array($Rez)) {
$url = $row['url']; //url to scrape
$id = $row['id'];
$content = file_get_contents($url);
$title = trim(htmlentities(getMetaTitle($content), ENT_QUOTES, 'UTF-8'));
if (empty($title)){$title=$url;}
//echo $title." <br>";
$TitleToUpdate="UPDATE urls
SET title='".$title."'
WHERE id='".$id."' ";
$UpdateTitle=mysql_query($TitleToUpdate);
}
mysql_close();
?>





