doudansui6650 2014-09-24 22:20
浏览 15
已采纳

PHP变量中的addcslashes返回空

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?