解析参数中有“:”的“/s?a=12&b=12.3.3.4:1233”时如何避免php parse_url return false?
How to avoid php parse_url return false when parse "/s?a=12&b=12.3.3.4:1233" which has ":" in the params?
如何在解析 ''/s?a=12&b=12.3.3.4:1233" 时避免 php parse_url return false": " 在参数中?
<?php
var_dump(parse_url('/s?a=12&b=12.3.3.4:1233', PHP_URL_QUERY));
returns
bool(false)
这里是在线运行测试结果:
同时在 php 7.1.7
中测试良好
print_r(parse_url('/s?a=12&b=12.3.3.4:1233', PHP_URL_QUERY));
return好:
a=12&b=12.3.3.4:1233
在 PHP7 中您可以省略 scheme
和 host
,但在该版本以下您不能。
因此您还应该始终包括方案和主机。
<?php
echo 'Without scheme and host'.PHP_EOL;
print_r(parse_url('/s?a=12&b=12.3.3.4:1233', PHP_URL_QUERY));
echo PHP_EOL.PHP_EOL;
echo 'With scheme and host'.PHP_EOL;
print_r(parse_url('http://example.com/s?a=12&b=12.3.3.4:1233', PHP_URL_QUERY));
7.0.0 - 7.2.0 的输出
Without scheme and host
a=12&b=12.3.3.4:1233
With scheme and host
a=12&b=12.3.3.4:1233
5.6.0 - 5.6.30、hhvm-3.18.5 - 3.22.0 的输出
Without scheme and host
With scheme and host
a=12&b=12.3.3.4:1233
如何在解析 ''/s?a=12&b=12.3.3.4:1233" 时避免 php parse_url return false": " 在参数中?
<?php
var_dump(parse_url('/s?a=12&b=12.3.3.4:1233', PHP_URL_QUERY));
returns
bool(false)
这里是在线运行测试结果:
同时在 php 7.1.7
中测试良好print_r(parse_url('/s?a=12&b=12.3.3.4:1233', PHP_URL_QUERY));
return好:
a=12&b=12.3.3.4:1233
在 PHP7 中您可以省略 scheme
和 host
,但在该版本以下您不能。
因此您还应该始终包括方案和主机。
<?php
echo 'Without scheme and host'.PHP_EOL;
print_r(parse_url('/s?a=12&b=12.3.3.4:1233', PHP_URL_QUERY));
echo PHP_EOL.PHP_EOL;
echo 'With scheme and host'.PHP_EOL;
print_r(parse_url('http://example.com/s?a=12&b=12.3.3.4:1233', PHP_URL_QUERY));
7.0.0 - 7.2.0 的输出
Without scheme and host
a=12&b=12.3.3.4:1233
With scheme and host
a=12&b=12.3.3.4:1233
5.6.0 - 5.6.30、hhvm-3.18.5 - 3.22.0 的输出
Without scheme and host
With scheme and host
a=12&b=12.3.3.4:1233