Insertion Sort in PHP With Example | How Does Insertion Sort Work in PHP
PHP Error Control Operator In Hindi | Error Control In PHP
PHP var_export() Function In Hindi | var_export() In PHP In Hindi
PHP Form validation | Validate User Input Data In PHP In Hindi
हैकिंग क्या है ? हैकिंग कितने प्रकार की होती है।
JavaScript "new Function" Syntax : JS "new Function" Syntax
AWS Storage Service In Hindi : Types of AWS Storage Services
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
PHP filter_var() Function
Modern web application में किसी भी type के data को store या process करने से पहले data को validate किया जाता है , ताकि applications को secure और reliable बनाया जा सके।
PHP by default कुछ functionalities provide की हैं जिनकी help से हम external data को validate कर सकें।
●●●
filter_var()
function का use अलग - अलग specified filter के according data को filter और sanitize करने के लिए।
filter_var(data, flag, options);
data
: filter / sanitize करने के लिए pass value । यह required value है।
flag
: filter_var()
function में कई अलग अलग तरह के flags किये जाते हैं। यह भी required value है।
options
: यह भी optional field है। यहां आप एक या एक से ज्यादा flags/options pass कर सकते हैं , अगर आप advance level के filtering करना चाहते हैं।
नीचे example में email को filter किया गया है।
function validate_email($email) {
// first remove all illegal characters.
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate e-mail
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo("$email is a valid email");
}
else {
echo("$email is not a valid email");
}
}
validate_email("johndoe@gmail");
validate_email("johndoe#gmail.com");
validate_email("johndoe@gmail.com");
Output
johndoe@gmail is not a valid email johndoe#gmail.com is not a valid email johndoe@gmail.com is a valid email
●●●
filter_var()
के साथ ctype_digit()
function का use करके आप mobile number easily validate कर सकते हैं।
function validate_mobile($mobile) {
// first remove all illegal characters.
$email = filter_var($mobile, FILTER_SANITIZE_DIGIT);
if (ctype_digit($mobile) && strlen($mobile)==10) {
echo("$mobile is valid mobileno");
}
else {
echo("$mobile is not valid mobileno");
}
}
validate_mobile("7889677889");
validate_mobile("788967788");
validate_mobile("78896778KL");
Output
7889677889 is valid mobileno 788967788 is not valid mobileno 78896778KL is not valid mobileno
Learn more about ctype functions in PHP
इसी तरह से filter_var()
function के साथ कई प्रकार से data को validate कर सकते हैं , इसके लिए कई तरह के filter flags की available हैं।
●●●
I hope , PHP में filter_var()
function क्या है और क्या काम करता है आप अच्छे से समझ गए होंगे ।
Loading ...
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook