我有一个评论系统,允许自动链接网址。我正在使用 cakephp,但解决方案更多的是 PHP。这就是正在发生的事情。
如果用户输入完全限定的网址http://
or https://
一切安好。
但如果他们进入www.scoobydoobydoo.com
它变成了http://cool-domain.com/www.scoobydoobydoo.com
。基本上 cakephp 知道 http|https 是外部 url,因此它可以与 http|https 一起使用,否则不会。
我的想法是在 url 上做一些 str 的事情,并让它插入 http(如果不存在)。不幸的是,无论我尝试什么,只会让事情变得更糟。我是菜鸟:)感谢任何帮助/指示。
thanks
编辑:发布解决方案片段。可能不是最好的,但感谢您的回答,至少我有一些东西。
<?php
$proto_scheme = parse_url($webAddress,PHP_URL_SCHEME);
if((!stristr($proto_scheme,'http')) || (!stristr($proto_scheme,'http'))){
$webAddress = 'http://'.$webAddress;
}
?>
$url = "blahblah.com";
// to clarify, this shouldn't be === false, but rather !== 0
if (0 !== strpos($url, 'http://') && 0 !== strpos($url, 'https://')) {
$url = "http://{$url}";
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)