when I try to remove special characters in a variable using the addcslashes eg addcslashes($this->description), "description" save the record in database but empty. If I remove addcslashes and just use $this->description saves normally.
1条回答 默认 最新
douzi1350 2014-09-24 22:24关注Maybe, you can use this function:
function clean($string) { $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens. $string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars. return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one. }First sanitise the string before you send to save in DB.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报