I use this code for creating a meta description:
// Read articles
$SQL = "SELECT id, CONCAT(introtext, `fulltext`) AS metatext
FROM jos_content
WHERE introtext>''
AND metadesc=''";
$rss = $db->query_read($SQL);
while($rs = $db->fetch($rss))
{
$metadesc = strip_tags($rs['metatext']);
//echo $rs['id'] . htmlspecialchars($metadesc); die;
while(strlen($metadesc) > 255)
{
$i = strrpos(substr($metadesc, 0, -1), '.');
if($i === false)
{
break;
}
$metadesc = substr($metadesc, 0, $i + 1);
}
$metadesc = $db->escape_string($metadesc);
// Write record
$SQL = "UPDATE jos_content
SET metadesc='$metadesc'
WHERE id=$rs[id]";
//echo htmlspecialchars($SQL); die;
$db->query_write($SQL);
if($db->errno)
{
echo $db->error;
die;
}
echo "Meta Description Article: $rs[id]<br />" . str_repeat(' ', 255);
flush();
}