使用http://upfront将网站的URL设置为字符串格式 [英] Format a website´s URL as a string with http:// upfront
问题描述
我有一个评论系统,该系统允许自动链接url.我正在使用cakephp,但解决方案更多是PHP.这是正在发生的事情.
I have a comment system that allows auto linking of url. I am using cakephp but the solution is more just PHP. here is what is happening.
如果用户使用http://
或https://
输入完全限定的url,则一切正常.
但是如果他们输入www.scoobydoobydoo.com
,它将变成http://cool-domain.com/www.scoobydoobydoo.com
.基本上,cakephp知道http | https是一个外部URL,因此它不能与http | https一起使用.
if the user enters fully qualified url with http://
or https://
everything is fine.
but if they enter www.scoobydoobydoo.com
it turns into http://cool-domain.com/www.scoobydoobydoo.com
. basically cakephp understands that http|https is an external url so it works with http|https not otherwise.
我的想法是对URL进行某种形式的str操作,并使其插入http(如果不存在的话).不幸的是,我所做的一切只会使情况变得更糟.我是菜鸟:)任何帮助/指针都表示赞赏.
My idea was to do some kind of str stuff on the url and get it to insert the http if not present. unfortunately whatever i try only makes it worse. I am noob :) any help / pointer is appreciated.
谢谢
发布解决方案摘要.可能不是最好的,但至少要感谢我的回答.
posting solution snippet. may not be the best but thanks to answer at least I have something.
<?php
$proto_scheme = parse_url($webAddress,PHP_URL_SCHEME);
if((!stristr($proto_scheme,'http')) || (!stristr($proto_scheme,'http'))){
$webAddress = 'http://'.$webAddress;
}
?>
推荐答案
尝试使用parse_url
函数: http://php.net/manual/en/function.parse-url.php
我认为这会对您有所帮助.
I think this will help you.
这篇关于使用http://upfront将网站的URL设置为字符串格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!