【问题标题】:HTML document was not declared未声明 HTML 文档
【发布时间】:2015-11-06 17:33:57
【问题描述】:

这是关于从 Mysql 表中以 CSV 形式检索数据:-

代码,我试过了:-

<?php
// mysql database connection details
    $host = "localhost";
    $username = "root";
    $password = "hello";
    $dbname = "mysql2csv";

// open connection to mysql database
    $connection = mysqli_connect($host, $username, $password, $dbname) or     die("Connection Error " . mysqli_error($connection));

// fetch mysql table rows
    $sql = "select * from tbl_books";
    $result = mysqli_query($connection, $sql) or die("Selection Error " .     mysqli_error($connection));

    $fp = fopen('books.csv', 'w');

    while($row = mysqli_fetch_assoc($result))
{
        fputcsv($fp, $row);
}

    fclose($fp);

//close the db connection
    mysqli_close($connection);

?>

获得的错误...

04:12:27.093 未声明 HTML 文档的字符编码。如果文档包含 US-ASCII 范围之外的字符,则文档将在某些浏览器配置中呈现乱码。页面的字符编码必须在文档或传输协议中声明。1 mysql2csv.php。

您的帮助将不胜感激...

【问题讨论】:

    标签: php html firefox


    【解决方案1】:

    将这些行添加到您的 html 标题中

    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding">
    

    编辑: 如果您使用的是 PHP 文件:

    header('Content-Type: text/html; charset=utf-8');
    

    【讨论】:

    • 我只是想在服务器上运行 php 脚本,我没有 HTML 标头
    • 你想在终端/命令行界面上运行这个吗?
    • 我在 localhost mysql 数据库上运行它,在运行时显示上述问题
    • 我的意思是你是通过浏览器运行这个脚本吗?还是使用命令行界面?
    • 可以加这个header('Content-Type: text/html; charset=utf-8');
    猜你喜欢
    • 2015-12-05
    • 2014-09-12
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多