将php查询结果导出到ascii txt文件
我是 PHP 新手,我有一个问题:如何将 php-mysql 查询结果导出到带有预定义空格的 ascii txt 文件中? 我在网络和书籍中进行了搜索,但没有找到具体的解决方案。有人可以帮我吗?提前致谢
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 me, please? Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要这些函数将查询结果转换为文本:
http://php.net/manual/en/function.mysql-fetch -assoc.php
http://php.net/manual/en/function.array-keys.php
对于文件写入:
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 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
您最好阅读有关如何按位写入文本文件的文档。有许多字符集用于存储驱动器上的文档。这取决于您定义的将数据保存在数据库中的字符集,以及您的 php 函数在获取相同数据时是否正在更改字符集。
这是字符集操作的示例(将 iso-8859-1 转换为 utf-8): http://www.php.net/manual/en/function.utf8-decode.php
您可能需要按位读取文件并转换该范围内的所有字符的 ascii 表并清除其他表,但除非您的文档采用除第一个源的 ascii 之外的其他类型,否则您可能会让该文件采用其预定义的字符集。
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.