如何设置特殊字符的子字符串


how can set substr for special chars?

如何将执行htmlspecialchars的文本substr发送给它。

保存在数据库中

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

带有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);
  }

并且仅改变"

尝试先解码后编码:

$str = htmlentities(
   substr(html_entity_decode($str, ENT_QUOTES),0,50)
,ENT_QUOTES);

在eval.in进行测试(链接即将过期