通过example.com时parse_url()返回错误 [英] parse_url() returns an error when example.com is passed
问题描述
根据以下代码,如果$host_name
是类似example.com
的PHP,则会返回一个通知:Message: Undefined index: host
,但是在完整的URL(例如http://example.com
)上,PHP返回example.com
.我试过if语句为FALSE和NULL,但没有用.
According to following code if $host_name
is something like example.com
PHP returns a notice: Message: Undefined index: host
but on full URLs like http://example.com
PHP returns example.com
. I tried if statements with FALSE and NULL but didn't work.
$host_name = $this->input->post('host_name');
$parse = parse_url($host_name);
$parse_url = $parse['host'];
如何修改脚本以接受example.com并将其返回?
How can I modify the script to accept example.com and return it?
推荐答案
-
升级您的php.
5.4.7 Fixed host recognition when scheme is ommitted and a leading component separator is present.
Upgrade your php.
5.4.7 Fixed host recognition when scheme is ommitted and a leading component separator is present.
手动添加方案:if(mb_substr($host_name, 0, 4) !== 'http') $host_name = 'http://' . $host_name;
这篇关于通过example.com时parse_url()返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!