簡體   English   中英

PHP-顯示特殊字符

[英]PHP - Show special characters

允許用戶輸入的代碼段

//fetch user input and pass it in URL
alertify.prompt("Please enter note/remarks for this Form (optional):", function (e,value) {
    if (e) {
               alertify.success("Form has been submitted");
               $.post(SITE_URL+"someController/someAction",$("#frm_submit").serialize()+ "&user_id="+user_id+"&comment="+value, function( data ) {
           });

    }else{
       alertify.error("Your Form is not submitted");
    }
});

用戶輸入: 每個Google員工的我的項目Google研發

發布表單后,輸入內容不完整,如下所示

echo $_POST['comment']打印“ 我的項目” Google R

在這里,如果用戶輸入特殊字符(如&作為注釋,則會中斷輸入

嘗試使用htmlentities($_POST['comment'])htmlspecialchars($_POST['comment'], ENT_QUOTES, 'UTF-8')但無法正常工作。

如何允許用戶輸入特殊字符?

PS:我沒有在數據庫中保存此值

正如Daan所建議的那樣, &打破了javascript中的URL。 請找到對我有用的更新代碼段

//fetch user input and pass it in URL
alertify.prompt("Please enter note/remarks for this Form (optional):", function (e,value) {
    if (e) {

               alertify.success("Form has been submitted");

               //encodes special characters in user comment
               var comment = encodeURIComponent(value);

               $.post(SITE_URL+"someController/someAction",$("#frm_submit").serialize()+ "&user_id="+user_id+"&comment="+comment, function( data ) {
           });

    }else{
       alertify.error("Your Form is not submitted");
    }
});

使用post參數發送數據。

$.ajax({
  type: "POST",
  url: your_url,
  data: { user_id: user_id, comment: value } 
});

嘗試這個:

stripslashes($_POST['comment'])

暫無
暫無

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

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