簡體   English   中英

以某種形式顯示西班牙語字符

[英]Show spanish characters in a form

我有一個表單,在文本區域中,我想顯示一些具有一些西班牙字符但編碼為html的文本。 問題在於,它顯示的是html代碼而不是西班牙字符。 我正在使用htmlentities在表單中顯示它。 我要顯示的代碼是:

<?php echo htmlentities($string, ENT_QUOTES, "UTF-8") ?>

任何想法還是我不應該以某種形式使用htmlentities? 謝謝!

編輯$string = 'á'

當我只執行<?php echo $string ;?>我得到á如果我做了<?php echo htmlentities($string, ENT_QUOTES, "UTF-8") ?>我會得到&aacute;

我很混亂!

如果我對您的理解正確,則需要使用...

<meta charset="utf-8">

在頁面標題中,然后...

<?php echo html_entity_decode($string, ENT_QUOTES); ?>

這會將您的HTML實體轉換回其正確的字符

您可以嘗試在文件頂部顯式添加內容類型,如下所示

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

如果已經將其編碼為html,則需要立即對其進行解碼。.您可以使用html_entity_decode html_entity_decode($string);

您要在表單中回顯的字符串應為&aacute; 從數據庫中,而不是返回á

$string = '&aacute;'; // your string as fetched from database
echo html_entity_decode($string);// this will display á in the textarea

在保存到數據庫之前,您需要

htmlentities($_POST['txtAreaName'], ENT_QUOTES, "UTF-8"); // return `&aacute;`

您可能正在尋找htmlspecialchars。

echo htmlspecialchars('<á>', ENT_COMPAT | ENT_HTML5, "UTF-8");

輸出&lt;á&gt;

暫無
暫無

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

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