I'm a noobie in PHP and I have a problem: how can I export a php-mysql query result into a ascii txt file with pre-definied spaces? I searched into the web and in my books but I didn't find a specific solution. Could anyone help 开发者_如何学Gome, please? Thanks in advance
You will need these functions to convert query result to text:
http://php.net/manual/en/function.mysql-fetch-assoc.php
http://php.net/manual/en/function.array-keys.php
For file writing:
http://www.php.net/manual/en/function.fopen.php
http://www.php.net/manual/en/function.fwrite.php
http://www.php.net/manual/en/function.fclose.php
You better read documents on how text files are bit-written. There are many charset used to memorized documents on your drive. It depends the charset that you've defined saving the data on your database and if your php function is changing the charset when it fetches the same data.
here's an example of charset manipulation (converts iso-8859-1 to utf-8) : http://www.php.net/manual/en/function.utf8-decode.php
you might want read your file bit-wised and converts all the chars that are in the range of the ascii table and sweep off the others, but unless your document is in an other type than ascii to the first origin, you probably let the file in its predefined charset.
精彩评论