2011-11-09 16 views
0

當我在JSON數據的軌道剝離html標籤與strip_tags的,它會返回錯誤的數據:用strip_tags使用JSON數據出了錯

the original data is: "<p><em><span style=\"font-size: 96px; \">test</span></em></p>" 
data.to_json is: "\"<p><em><span style=\\\"font-size: 96px; \\\">\\u9ed1\\u4f53\\u5b57\\u54e6</span></em></p>\"" 
the stripped data that after strip_tags is: "\"" 

誰能告訴我原因或其他解決辦法?

回答

0

更改爲了:

strip_tags(data).to_json 

你會得到 「測試」 如預期。

原因是html掃描儀(由strip_tags使用)剝去編碼的「測試」值。

+0

哦,對不起,我不能。我想要得到一個模型集的json數據,而且我不希望將strip_tags與模型一個接一個地與模型的每個屬性相關聯。 – blankyao

+0

你有其他想法嗎? – blankyao