-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.php
59 lines (48 loc) · 1.23 KB
/
filter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
<body>
<?php
//Remove all tags
$str = "<h1>Hello World!</h1>";
$newstr = filter_var($str, FILTER_SANITIZE_STRING); //remove tags i.e. h1
echo $newstr . "<br>";
//Check for integer number
$int = 100;
if (!filter_var($int, FILTER_VALIDATE_INT) === false) { //check whether $int is integer
echo("Integer is valid");
} else {
echo("Integer is not valid");
}
echo "<br>";
$email = "john.doe@example.com";
// Remove all illegal characters from email
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
//echo $email;
// Validate e-mail
if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
echo("$email is a valid email address");
} else {
echo("$email is not a valid email address");
}
//Check for IP
echo "<br>";
$ip = "127.0.0.";
if (filter_var($ip, FILTER_VALIDATE_IP)) { //check for valid ip
echo("$ip is a valid IP address");
} else {
echo("$ip is not a valid IP address");
}
echo "<br>";
//Check for valid URL
$url = "https://www.w3schools.com";
// Remove all illegal characters from a url
$url = filter_var($url, FILTER_SANITIZE_URL);
// Validate url
if (!filter_var($url, FILTER_VALIDATE_URL) === false) {
echo("$url is a valid URL");
} else {
echo("$url is not a valid URL");
}
?>
</body>
</html>