簡體   English   中英

PHP刪除HTML標記后的所有內容

[英]PHP removing everything after HTML tags

我有一個contenteditable div像這樣:

<form>
    <div name="new_post" class="post" contenteditable="true"></div>
    <button type="submit">Submit</button>
</form>

contenteditable div允許使用粗體斜體標簽,但不允許其他標簽

我的問題是,如果用戶Hello there <u>world</u>!類似Hello there <u>world</u>! ,它將以Hello there保存在數據庫中。 似乎刪除了標簽后的所有內容,但我不知道為什么。

我正在使用AJAX和PHP處理帖子,因此這里是其余的代碼。

阿賈克斯:

$(document).ready(function() {
    $(document).on("submit", "form", function(event) {
        event.preventDefault();
        alert($('.post').html()); // added this to debug it. This prints "Hello there &lt;u&gt;world&lt;/u&gt;!"
        $.ajax({
            url: 'php/post.php',
            type: 'POST',
            dataType: 'json',
            data: $(this).serialize() + "&post_field=" + $('.post').html(),
            success: function(data) {
                alert(data.message);
            }
        });
    });
});

PHP:

<?php
    $post = $_POST["post_field"];

    // query to insert post into database goes here

    $array = array('message' => $post);

    echo json_encode($array);
?>

請幫忙!

更改:

$('.post').html()

至:

encodeURIComponent($('.post').html())

HTML字符需要在URL參數中編碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM