Hi, I've made a function named build() that outputs a mysql table into a text file based on the users format using special tags. This is what it looks like:
function build() {
if ($config["autobuild"] == 1) {
$fd = fopen ($config["news_path"]."news.txt" , "w");
if ($config["postlimit"] == 0) {
$query["build"] = mysql_query("SELECT news, subject, user, DAYOFMONTH(stamp) as day, YEAR(stamp) as year, HOUR(stamp) as hour, MINUTE(stamp) as minute, SECOND(stamp) as second FROM news ORDER BY stamp");
} else {
$query["build"] = mysql_query("SELECT news, subject, user, DAYOFMONTH(stamp) as day, YEAR(stamp) as year, HOUR(stamp) as hour, MINUTE(stamp) as minute, SECOND(stamp) as second FROM news ORDER BY stamp LIMIT 0, ".$config["postlimit"]);
}
if ($line = mysql_fetch_assoc($query["build"])) {
do {
$query["author"] = mysql_query("SELECT * FROM users WHERE username = '".$line["author"]."'");
$author = mysql_fetch_assoc($query["author"]);
if (strpos("+", $line["time_zone"])) {
$stamp = mktime(($line["hour"] + substr($line["time_zone"], 1)), $line["minute"], $line["second"], $line["month"], $line["day"], $line["year"]);
} elseif (strpos("-", $line["time_zone"])) {
$stamp = mktime(($line["hour"] - substr($line["time_zone"], 1)), $line["minute"], $line["second"], $line["month"], $line["day"], $line["year"]);
}
$news2 = $line["news"];
if ($config["autolink"] == 1) {
$news2 = preg_replace("/([\w\/])(www.[a-z0-9-]+.[a-z0-9-]+)/i", "$1http://$2", $news2);
$news2 = preg_replace("/([\w]+:\/\/[\w-?&;#~=.\/@]+[\w\/])/i", "<a href=\"_blank\" HREF=\"$1\">$1</A>", $news2);
$news2 = preg_replace("/([\w-?&;#~=.\/]+@([?)[a-zA-Z0-9-.]+.([a-zA-Z]{2,3}|[0-9]{1,3})(]?))/i", "<a href=\"mailto:$1\">$1</A>", $news2); //make all emails hot links
}
$date = $config["date_format"];
$date = str_replace("<Day>", gmdate("j", $stamp), $date);
$date = str_replace("<WeekDay>", gmdate("l", $stamp), $date);
$date = str_replace("<Year>", gmdate("Y", $stamp), $date);
$date = str_replace("<YearShort>", gmdate("y", $stamp), $date);
$date = str_replace("<AMPM>", gmdate("A", $stamp), $date);
$date = str_replace("<Minute>", gmdate("i", $stamp), $date);
$date = str_replace("<Second>", gmdate("s", $stamp), $date);
$date = str_replace("<12Hour>", gmdate("g", $stamp), $date);
$date = str_replace("<24Hour>", gmdate("G", $stamp), $date);
$date = str_replace("<Month>", gmdate("F", $stamp), $date);
$date = str_replace("<MonthShort>", gmdate("M", $stamp), $date);
$date = str_replace("<Swatch>", gmdate("B", $stamp), $date);
$format = $config["news_format"];
$format = str_replace("<News>", $news2, $format);
$format = str_replace("<Subject>", $line["subject"], $format);
$format = str_replace("<Author>", $author["username"], $format);
$format = str_replace("<AuthorEmail>", $author["email"], $format);
$format = str_replace("<DateTime>", $date, $format);
if ($config["use_comments"] == 1) {
$format = str_replace("<CommentURL>", "comments.php?id=".$line["id"], $format);
}
if ($config["filter_words"] == 1) {
$file = file("filter.txt");
for ($filternum=0;$filternum<=count($file);$filternum++) {
$format = str_replace($file[$filternum], filterstars($file[$filternum]), $format);
}
if ($config["html"] == 0) {
$format = strip_tags($format);
}
if ($config["autobr"] == 1) {
$format = str_replace("\n", "<br>", $format);
}
$fout = fwrite ($fd , $format);
fclose($fd);
echo $format;
exit;
}
} while ($line = mysql_fetch_assoc($query["build"]));
} else {
$fout = fwrite ($fd , "No news available");
fclose($fd);
}
}
}
But when it writes to it, there is just a blank text file.