[英]Special character output in html from mysql
I am using a plugin in Wordpress that stores some html code in a field. 我在Wordpress中使用一个插件,在一个字段中存储一些HTML代码。 This column is
mediumtext utf8_general_ci
此
mediumtext utf8_general_ci
When I want to output this information all special characters such as " ´ ' ...
and some others are displayed as black diamonds with a question mark inside
当我想输出这些信息时,所有特殊字符,如
" ´ ' ...
和其他一些字符显示为黑色钻石,里面有问号
When the plugin shows this text it's perfect. 当插件显示此文本时,它是完美的。 This is in the head:
这是在头脑中:
<meta charset="UTF-8" />
When I output elsewhere I have this in my head and all those characters are lost: 当我在其他地方输出时,我的头脑中有这个,所有这些字符都丢失了:
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
Characters are properly stored in MYSQL, and I output it via PHP like this 字符正确存储在MYSQL中,我通过PHP输出它
ob_start();?>
some html
<?php echo $row4['details'];?> <- this is the field im talking about
some html
<?php
$details = ob_get_clean();
and later just: 后来只是:
echo $details;
I have read quite enough and the charset is always mentioned, but I think mine is OK. 我已经阅读了足够的内容,并且总是提到字符集,但我认为我的还可以。
Thanks for the help! 谢谢您的帮助!
Edit: Adding Full example 编辑:添加完整示例
Text shown in WP. WP中显示的文字。 As I said in a comment this might have been copy/pasted from MS Word into Worpress by an editor.
正如我在评论中所说,这可能是由编辑将MS Word复制/粘贴到Worpress中。
8. Choose the verb to complete the sentence.
______ you ever _____ the proverb, “Time is gold”?
Has… heard…
Have… hear…
Have… heard…
Stored in database like this (don't look into correct/user answer that works properly) 像这样存储在数据库中(不要查看正确/正确的用户答案)
<span class='watupro_num'>8. </span>Choose the verb to complete the sentence.</p>
<p>______ you ever _____ the proverb, “Time is gold”?</p></div>
<ul>
<li class='answer'><span class='answer'>Has… heard…</span></li>
<li class='answer user-answer'><span class='answer'>Have… hear…</span></li>
<li class='answer correct-answer'><span class='answer'>Have… heard…</span></li>
</ul>
Text shown out of database (what im working on) 从数据库中显示的文本(我正在进行的工作)
8. Choose the verb to complete the sentence.
______ you ever _____ the proverb, �Time is gold�?
Has� heard�
Have� hear�
Have� heard�
Text shown after utf8_encode()
thanks to Kirit Patel 由于Kirit Patel,在
utf8_encode()
之后显示的文字
8. Choose the verb to complete the sentence.
______ you ever _____ the proverb, Time is gold?
Has heard
Have hear
Have heard
I've just discovered characters are still there. 我刚发现角色还在那里。 I can see a box with numbers while editing (not displayed in preview).
编辑时我可以看到一个带数字的框(未在预览中显示)。
You can use just like 你可以像使用一样
<?php
echo utf8_encode($row4['details']);
?>
Hope this helps you. 希望这对你有所帮助。
"Black diamonds" are discussed here . 这里讨论“黑钻石”。 The "Someting like this" shows
0093
, which is an invalid utf8 code for some flavor of quote; “Someting like this”显示
0093
,这是一个无效的utf8代码,用于某种引用的味道; on the other hand, hex 93, interpreted as latin1 is “
. 另一方面,hex 93,解释为latin1是
“
。
Can you simply switch to ascii quotes and apostrophes? 你能简单地切换到ascii引号和撇号吗?
Otherwise, you need to use utf8 throughout -- starting with whatever is generating the hex 93. 否则,您需要始终使用utf8 - 从生成十六进制93的任何内容开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.