2015-02-07 80 views
2

我怎麼能substr一個文本執行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 � 

坦克

UPDATE

我用這個

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

,只是改變"

+1

您是否嘗試過用特殊字符字符串解碼? – chility 2015-02-07 20:33:21

+0

是的,我做了,但沒有工作 – Simon 2015-02-07 20:35:55

+0

然後,我認爲你需要向我們展示代碼,告訴我們發生了什麼以及你想要發生什麼_exactly。 – MAV 2015-02-07 20:38:21

回答

1

前SUBSTR嘗試decodeencode後:

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

Test at eval.in鏈接即將到期