如何为特殊字符设置 substr?

how can set substr for special chars?

我怎样才能 substr 对它执行 htmlspecialchars 的文本。

保存在数据库中

some text " some text " some text
' some text ' some text 'some text' some text '
some text 'some text ' some text ' some text '

with htmlspecialchars(我想 substr 来自这篇文章)

some text " some text " some text ' some text ' some text ' some text '
some text ' some text ' some text ' some text ' some text '

当 substr :

some text " some text " some text ' some text �

坦克

更新

我用这个

 if( strlen($text)>100){
    $s = html_entity_decode($text);
    $shorten = substr($s,0,50);
    echo htmlentities($shorten);
  }

并且只是改变 "

之后尝试decode before substr and encode
$str = htmlentities(
   substr(html_entity_decode($str, ENT_QUOTES),0,50)
,ENT_QUOTES);

Test at eval.inlink即将到期