I’m trying to create a tab delimited file with PHP and having some troubles. Basically my tabs, and line breaks ie \t and \n end up being printed out instead of converted to what they are supposed to be.
My code is simple:
$sql = 'SELECT * FROM products';
$res = mysql_query($sql);
$page_print = 'id \t title \t description \t price';
while($row = mysql_fetch_array($res)) {
$page_print .= $row['product_id'] . ' \t ' . $row['product_name'] . ' \t ' . strip_tags($row['product_content']) . ' \t ' . $row['product_price'] . '\n';
}
$page_print = sanitize_output($page_print);
$myFile = "products.txt";
$fh = fopen($myFile, 'w');
$stringData = trim($page_print);
fwrite($fh, $stringData);
fclose($fh);
What am I doing wrong here?
You need to append them using double quotes (“).
quote from PHP: