xref: /PHP-5.6/ext/filter/tests/015.phpt (revision a888ee43)
1--TEST--
2filter_var() and FILTER_VALIDATE_URL
3--SKIPIF--
4<?php if (!extension_loaded("filter")) die("skip"); ?>
5--FILE--
6<?php
7
8$values = Array(
9'http://example.com/index.html',
10'http://www.example.com/index.php',
11'http://www.example/img/test.png',
12'http://www.example/img/dir/',
13'http://www.example/img/dir',
14'http//www.example/wrong/url/',
15'http:/www.example',
16'file:///tmp/test.c',
17'ftp://ftp.example.com/tmp/',
18'/tmp/test.c',
19'/',
20'http://',
21'http:/',
22'http:',
23'http',
24'',
25-1,
26array(),
27'mailto:foo@bar.com',
28'news:news.php.net',
29'file://foo/bar',
30"http://\r\n/bar",
31"http://example.com:qq",
32"http://example.com:-2",
33"http://example.com:65536",
34"http://example.com:65537",
35);
36foreach ($values as $value) {
37	var_dump(filter_var($value, FILTER_VALIDATE_URL));
38}
39
40
41var_dump(filter_var("qwe", FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED));
42var_dump(filter_var("http://qwe", FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED));
43var_dump(filter_var("http://", FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED));
44var_dump(filter_var("/tmp/test", FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED));
45var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED));
46var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED));
47var_dump(filter_var("http://www.example.com/path/at/the/server/", FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED));
48var_dump(filter_var("http://www.example.com/index.html", FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED));
49var_dump(filter_var("http://www.example.com/index.php?a=b&c=d", FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED));
50
51echo "Done\n";
52?>
53--EXPECT--
54string(29) "http://example.com/index.html"
55string(32) "http://www.example.com/index.php"
56string(31) "http://www.example/img/test.png"
57string(27) "http://www.example/img/dir/"
58string(26) "http://www.example/img/dir"
59bool(false)
60bool(false)
61string(18) "file:///tmp/test.c"
62string(26) "ftp://ftp.example.com/tmp/"
63bool(false)
64bool(false)
65bool(false)
66bool(false)
67bool(false)
68bool(false)
69bool(false)
70bool(false)
71bool(false)
72string(18) "mailto:foo@bar.com"
73string(17) "news:news.php.net"
74string(14) "file://foo/bar"
75bool(false)
76bool(false)
77bool(false)
78bool(false)
79bool(false)
80bool(false)
81string(10) "http://qwe"
82bool(false)
83bool(false)
84string(22) "http://www.example.com"
85bool(false)
86string(42) "http://www.example.com/path/at/the/server/"
87bool(false)
88string(40) "http://www.example.com/index.php?a=b&c=d"
89Done
90