In codeigniter how to remove unwanted characters or symbols in string In codeigniter how to remove unwanted characters or symbols in string codeigniter codeigniter

In codeigniter how to remove unwanted characters or symbols in string


you can do

$data = array(    'designationName' => preg_replace('/[^a-zA-Z0-9-_\.]/','', $row[$ex_start + 3])    'designationDate' => date('Y-m-d'),    'status_idstatus' => '1');

Note: This will allow plain text+numbers to save. No, any special chars will pass


Edit 01

If you need to allow some special chars (all keyboard chars)

 preg_replace('/[^A-Za-z0-9_~`\/@!$.%^#&*\\()+-=]/','', $row[$ex_start + 3])

Or you can use Escaping Queries in codeigniter

  1. $this->db->escape()
  2. $this->db->escape_str()
  3. $this->db->escape_like_str()