xref: /PHP-7.1/ext/filter/tests/056.phpt (revision 7af945e2)
1--TEST--
2filter_var() and FILTER_VALIDATE_DOMAIN
3--SKIPIF--
4<?php if (!extension_loaded("filter")) die("skip"); ?>
5--FILE--
6<?php
7
8$values = Array(
9'example.com',
10'www.thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com',
11'toolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolong.com',
12'eauBcFReEmjLcoZwI0RuONNnwU4H9r151juCaqTI5VeIP5jcYIqhx1lh5vV00l2rTs6y7hOp7rYw42QZiq6VIzjcYrRm8gFRMk9U9Wi1grL8Mr5kLVloYLthHgyA94QK3SaXCATklxgo6XvcbXIqAGG7U0KxTr8hJJU1p2ZQ2mXHmp4DhYP8N9SRuEKzaCPcSIcW7uj21jZqBigsLsNAXEzU8SPXZjmVQVtwQATPWeWyGW4GuJhjP4Q8o0.com',
13'kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.CQ1oT5Uq3jJt6Uhy3VH9u3Gi5YhfZCvZVKgLlaXNFhVKB1zJxvunR7SJa.com.',
14'cont-ains.h-yph-en-s.com',
15'..com',
16'ab..cc.dd',
17'a.-bc.com',
18'ab.cd-.com',
19'-.abc.com',
20'abc.-.abc.com',
21'underscore_.example.com',
22'',
23-1,
24array(),
25'\r\n',
26);
27foreach ($values as $value) {
28	var_dump(filter_var($value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME));
29}
30
31var_dump(filter_var('_example.com', FILTER_VALIDATE_DOMAIN));
32var_dump(filter_var('_example.com', FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME));
33var_dump(filter_var('test_.example.com', FILTER_VALIDATE_DOMAIN));
34var_dump(filter_var('test_.example.com', FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME));
35var_dump(filter_var('te_st.example.com', FILTER_VALIDATE_DOMAIN));
36var_dump(filter_var('te_st.example.com', FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME));
37var_dump(filter_var('test._example.com', FILTER_VALIDATE_DOMAIN));
38var_dump(filter_var('test._example.com', FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME));
39
40echo "Done\n";
41?>
42--EXPECT--
43string(11) "example.com"
44string(71) "www.thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com"
45bool(false)
46bool(false)
47string(254) "kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.CQ1oT5Uq3jJt6Uhy3VH9u3Gi5YhfZCvZVKgLlaXNFhVKB1zJxvunR7SJa.com."
48string(24) "cont-ains.h-yph-en-s.com"
49bool(false)
50bool(false)
51bool(false)
52bool(false)
53bool(false)
54bool(false)
55bool(false)
56bool(false)
57bool(false)
58bool(false)
59bool(false)
60string(12) "_example.com"
61bool(false)
62string(17) "test_.example.com"
63bool(false)
64string(17) "te_st.example.com"
65bool(false)
66string(17) "test._example.com"
67bool(false)
68Done
69