通过example.com时parse_url()返回错误 [英] parse_url() returns an error when example.com is passed

查看:75
本文介绍了通过example.com时parse_url()返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据以下代码,如果$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?

推荐答案

  1. 升级您的php. 5.4.7 Fixed host recognition when scheme is ommitted and a leading component separator is present.

  1. 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆