想要存储像Apostrophe等特殊字符..在yii模型中 - > save()

时间:2015-06-30 07:12:03

标签: php yii

我需要在我的模型中存储特殊的chanrate,保存, 我的$model->attributes就像是

Array
(
    [name] => Indian Identity
    [description] => Description from 'Ranjit Hoskote’s The Complicit Observer provides an art-historical account of Sudhir Patwardhan’s career, which spans over three decades and ranges across painting, drawing, township. 
    [clsfication] => this is classification 
   )

如何使用model->save()

存储特殊字符

2 个答案:

答案 0 :(得分:2)

您可以使用PHP本机函数addslashes

代码:

$model->setAttributes([
   'name' => addslashes('name'),
   'description' => addslashes('description'),
   'clsfication' => addslashes('clsfication'),
]);
$model->save();

答案 1 :(得分:0)

Array
(
    [name] => Indian Identity
    [description] => Description from 'Ranjit Hoskote\'s The Complicit Observer provides an art-historical account of Sudhir Patwardhan\'s career, which spans over three decades and ranges across painting, drawing, township.' 
    [clsfication] => this is classification 
   )

试试这个。并告诉我它是否有效。