You could also get rid of all of these lines:
var = ("$text");
$varlength = strlen($var);
$limit = 500;
if ($varlength > $limit) {
$var = substr($var,0,$limit);
}
and just make MySQL do all the work for you, like so:
$tmp=mysql_query("SELECT title, category, date, SUBSTRING(text, 1, 200) AS text FROM article ORDER BY id DESC");