Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 作为HTML实体保存到数据库的HTML标记_Php_Html_Mysql_Utf 8_Tinymce - Fatal编程技术网

Php 作为HTML实体保存到数据库的HTML标记

Php 作为HTML实体保存到数据库的HTML标记,php,html,mysql,utf-8,tinymce,Php,Html,Mysql,Utf 8,Tinymce,我正在使用以下代码更新数据库中的值: function text_save( $page_name, $page_title, $page_text ) { $servername = "127.0.0.1"; $username = "abcd"; $password = "password"; $dbname = "thedatabase"; // Create connection $conn = new mysqli( $servern

我正在使用以下代码更新数据库中的值:

function text_save( $page_name, $page_title, $page_text ) {

    $servername = "127.0.0.1";
    $username = "abcd";
    $password = "password";
    $dbname = "thedatabase";

    // Create connection
    $conn = new mysqli( $servername, $username, $password, $dbname );

    // Check connection
    if ( $conn->connect_error ) {
        die( "Connection failed: " . $conn->connect_error );
    }

    $page_content = $page_text;

    $sql = "UPDATE text SET page_title=?, page_text=? WHERE text_name=?";

    // prepare and bind
    $stmt = $conn->prepare( $sql );

    // check whether the prepare() succeeded
    if ( $stmt === false ) {    
        trigger_error( $this->mysqli->error, E_USER_ERROR );
    }

    $stmt->bind_param( 'sss', $page_title, $page_content, $page_name );

    $stmt->execute();

    print '<p>Text saved</p>';

    $stmt->close();
    $conn->close();
}
但是,如果我手动将
$page\u content
的值设置为
测试

e、 g.
$page_content=“test

而不是
$page\u content=$page\u text

它以以下形式保存到数据库:

<p>test</p>
测试

我需要将HTML保存到数据库中,而不转换为HTML实体,即作为
test

而不是
ptest/p

这是我迄今为止尝试过的:

将页面设置为utf8-

将表单设置为utf8-
接受charset=“UTF-8”

将连接设置为utf8-
mysqli_set_charset($conn,“utf8”)

使用-
entity\u编码设置tinymce init:“raw”

我在这里做错了什么,为什么手动设置变量而不是使用表单变量值(看起来相同)时HTML字符串保存正确


非常感谢

我认为问题出在编辑上

在插入数据库并显示给我们之前,您能否尝试打印$page_content的值

也请看这篇文章。

您可能正在寻找html实体解码功能


小心注射之类的东西。

试着把你的感谢放在上面Micaela,我刚刚尝试按照建议添加完整的meta标签,但不幸的是没有成功。我已经在页面上找到了。是的,是tinymce编辑,谢谢@wilo087!即使var_dump显示字符串(23)“test

”,HTML已经转换为实体,我也应该选择与额外实体字符相关的字符串(23)。html_实体_解码为我修复了它,非常感谢!
<p>test</p>
$page_content = html_entity_decode($page_text);