Last active
June 24, 2020 03:23
-
-
Save ronakjain2012/464262bf7d3194e7cce23f5586f27d8f to your computer and use it in GitHub Desktop.
A sanitizing class can be used for different type of inputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommonFunctions | |
{ | |
public static function sanitize_number($number) | |
{ | |
return filter_var($number, FILTER_SANITIZE_NUMBER_INT); | |
} | |
public static function sanitize_decimal($decimal) | |
{ | |
return filter_var($decimal, FILTER_SANITIZE_NUMBER_FLOAT); | |
} | |
public static function sanitize_string($string) | |
{ | |
$string = htmlspecialchars($string); | |
//$string = addslashes($string); | |
return filter_var($string, FILTER_SANITIZE_STRING); | |
} | |
public static function sanitize_html($string) | |
{ | |
$string = htmlspecialchars($string, '<a><strong><em><hr><br><p><u><ul><ol><li><dl><dt><dd><table><thead><tr><th><tbody><td><tfoot>'); | |
//$string = addslashes($string); | |
return filter_var($string, FILTER_SANITIZE_STRING); | |
} | |
public static function sanitize_url($url) | |
{ | |
return filter_var($url, FILTER_SANITIZE_URL); | |
} | |
public static function sanitize_slug($string) | |
{ | |
$string = str_slug($string); // Laravel Helper | |
return filter_var($string, FILTER_SANITIZE_URL); | |
} | |
public static function sanitize_email($string) | |
{ | |
return filter_var($string, FILTER_SANITIZE_EMAIL); | |
} | |
public static function nl2br($content) | |
{ | |
return (str_replace(array('<br>', '<br />', '<br>', '<br/>'), '', nl2br($content))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment