[英]Simple bullet point issue
I am trying to catch bullet points which was given in textfield and trying to replace it with something else, because it is being shown as ?
我试图捕获在文本字段中给出的要点,并尝试将其替换为其他内容,因为它显示为
?
instead of • after rendering the given text to the user. 而不是•将给定文本呈现给用户之后。 I tested like this: I wrote text with bullet points in word and copy-pasted into textfield.
我进行了如下测试:我在单词中用点符号编写了文本,然后将其粘贴到文本字段中。
My vision is this: 我的愿景是:
$test = strstr($input,'•');
if($test){ echo "bullet point found!";
}
but it is not working or not catching, or •
但它不起作用或无法捕获,或
•
is the wrong regexp to catch the bullet points. 正则表达式是错误的正则表达式。
strstr
is unlikely to catch •
when you specify •
•
当您指定•
时, strstr
不太可能抓住•
because the former is a native character, and the latter a HTML entity. 因为前者是本地字符,而后者是HTML实体。
It doesn't matter though: you should fix the underlying issue instead. 但这并不重要:您应该改正根本问题。
You're likely to have an encoding problem that's not limited to bullet points. 您可能遇到的编码问题不仅限于项目符号。 Seeing a character means that you are feeding a non-UTF-8 character into UTF-8 output.
看到一个-字符意味着您正在将非UTF-8字符输入到UTF-8输出中。
Reasons for this could be: 原因可能是:
A source file (where the character is stored) that is saved in the wrong encoding, eg Windows-1252 instead of UTF-8 (check the "Save As..." dialog of your IDE) 以错误的编码保存的源文件(存储字符),例如Windows-1252而不是UTF-8(检查IDE的“另存为...”对话框)
A database connection that uses latin1
as the connection encoding (even though the tables are UTF-8) 使用
latin1
作为连接编码的数据库连接(即使表是UTF-8)
See UTF-8 all the way through for a comprehensive list of things to look at. 完整了解UTF-8,以获取要查看的内容的完整列表。
Try •
尝试
•
instead of •
而不是
•
. 。
See Special Characters in HTML. 请参见HTML中的特殊字符。
It's likely that the HTML isn't passing &bull, but the HTML equivilent. HTML可能没有通过&bull,而是HTML等价的。
If that doesn't work to find it, look into HTMLEntities() , which may realistically be the better way to go (unless maybe you're ONLY looking to deal with bullets). 如果找不到它,请查看HTMLEntities() ,这实际上可能是更好的方法(除非您可能只是想处理子弹)。
EDIT: Decode the HTML with html_entity_decode() , re-encode to the user with HTMLEntities(). 编辑:与解码HTML html_entity_decode() ,重新编码到用户与ヶ辆()。
First, before checking the input make sure to encode all characters into its HTML equivalents (which •
is). 首先,在检查输入之前,请确保将所有字符编码为等效的HTML(
•
是)。 So like this: 像这样:
$test = strstr(htmlentities($input), '•');
if($test) {
echo "bullet point found!";
}
However, if you encode your input using htmlentities
, all UTF-8 characters should be rendered fine to the user afterwards, as the storage won't need to deal with UTF-8 anymore, thus eliminating artifacts. 但是,如果您使用
htmlentities
编码输入,则以后所有UTF-8字符都应呈现给用户,因为存储不再需要处理UTF-8,从而消除了工件。
Also: Please make sure you are escaping user input when saving it into the database, preferably using equivalents of bound parameters as seen in PDO. 另外:请确保在将用户输入保存到数据库时转义用户输入,最好使用等效的绑定参数(如PDO中所示)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.