它给我的阿拉伯回声子? 我的数据末尾的标记已被回复[重复]

它给我的阿拉伯回声子? 我的数据末尾的标记已被回复[重复]

问题描述:

This question already has an answer here:

I am using php and mysql and I want to echo a part of data from row one

I used the command:

<? echo substr($row['text'],0,500); ?>

It will get 500 characters from the $row of text but at end ? appears. I am using Arabic text, which may be the reason.

Since the Arabic text are joined with each other may be it's not ended and that's why when it breaks at the time of the join which each other and if keep the join it will be more then 500 characters so I get the gives ?

How can I fix it so a question mark does not appear at the end?

</div>

此问题已经存在 这里有一个答案: p>

  • php substr()函数,utf-8在末尾留下�标记 7 answers span> li> ul> div>

    我正在使用 php和mysql我希望从第一行回显一部分数据 p>

    我使用了命令: p>

     &lt;?  echo substr($ row ['text'],0,500);  ?&gt; 
      code>  pre> 
     
     

    它将从$ row文本中获得500个字符,但最后会出现? strong>。 我正在使用阿拉伯语文本,这可能是原因。 p>

    由于阿拉伯语文本相互连接可能它没有结束,这就是为什么当它在连接时断开时 彼此如果保持联接将超过500个字符,所以我得到了? strong> p>

    如何修复它以便不出现问号 在结束? p> div>

It’s definitely a UTF-8 encoding issue. And the solution is to use mb_substr instead of plain substr like so:

<? echo mb_substr($row['text'],0,500,"utf-8"); ?>