strip_tags enough to remove HTML from string?

て烟熏妆下的殇ゞ 提交于 2019-12-02 04:22:29

I find that there's no single function for idiot-proofing user inputs. Best to mix a few together:

$val = trim($val);
$val = strip_tags($val);
$val = htmlentities($val, ENT_QUOTES, 'UTF-8'); // convert funky chars to html entities
$pat = array("\r\n", "\n\r", "\n", "\r"); // remove returns
$val = str_replace($pat, '', $val);
$pat = array('/^\s+/', '/\s{2,}/', '/\s+\$/'); // remove multiple whitespaces
$rep = array('', ' ', '');
$val = preg_replace($pat, $rep, $val);
$val = trim($val);
$val = mysql_real_escape_string($val); // excellent final step for MySQL entry
Keyne Viana

Regex could fit well with less code:

^[A-Z]'?[- a-zA-Z]( [a-zA-Z])*$

Here we have good examples:

Regex for names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!