I have some variables from database. So Can anybody tell me What would be the best method to sanitize these data before before using them (echoing)?
This is my variables -
$username
$email
$mobile
$domain
$sub_domain
$cpanel_username
$cpanel_password
$period
$domain_registered
So I tried to sanitize them using these method.
$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);
Can somebody tell me this way is correct or not? Thank you.