我有一些来自数据库的变量。那么任何人都可以告诉我在使用它们之前清理这些数据的最佳方法是什么(回声)?
这是我的变量 -
$username
$email
$mobile
$domain
$sub_domain
$cpanel_username
$cpanel_password
$period
$domain_registered
所以我尝试使用这些方法消毒它们。
$db_username = preg_replace("/[^a-zA-Z0-9_\-]+/", "", $username);
$db_email = filter_var($email, FILTER_SANITIZE_EMAIL);
$db_mobile = filter_var($mobile,FILTER_SANITIZE_NUMBER_INT);
$db_domain = filter_var($domain, FILTER_SANITIZE_URL);
$db_subDomain = filter_var($sub_domain, FILTER_SANITIZE_URL);
$db_cpanelUsername = preg_replace("/[^a-zA-Z0-9_\-]+/", "", $cpanel_username);
$db_cpanelUassword = $cpanel_password;
$db_period = (int)$period;
$db_domainRegistered = preg_replace("([^0-9-])", "", $domain_registered);
有人能告诉我这种方式是否正确? 谢谢。