regex - PHP - Filter unwanted elements from database input and update -
i use below method strip away unwanted characters gets inserted or updated in database.
to honest want allow following characters other regular letters , numbers: '
, -
, )
, :
... , few others. pretty characters allow write regular phrase.
am going @ right way? preg_replace
strips away spaces strings. how can make stop? how can add wanted characters preg_replace?
public function strip($arr = array()) { if (!is_array($arr) || !count($arr)) { return array(); } $returnarray = array(); foreach($arr $key => $val) { $val = $this->db->mysqli->real_escape_string($val); $val = strip_tags($val); //$val = preg_replace("/[^a-za-z0-9]/", '', $val); $returnarray[$key] = $val; } return $returnarray; }
[^a-za-z0-9\s]
allow characters a-z or a-z or numbers 0-9 , whitespaces. \s
stands whitespaces if want add symbols need escape them \
if used in regex $
[^\$]
if need creating regex can use regex101.com
Comments
Post a Comment