Yii将基本Url附加到href

Yii将基本Url附加到href,yii,hyperlink,href,Yii,Hyperlink,Href,我的网页上有外部链接: <a target="_blank" rel="nofollow" href=<?php echo $r['url'] ;?>> VISIT STORE </a> 试试这个: <?php echo CHtml::link('Google',

我的网页上有外部链接:

<a target="_blank" rel="nofollow" href=<?php echo $r['url'] ;?>>
                                                VISIT STORE
                                               </a>
试试这个:

<?php echo CHtml::link('Google', '//www.google.com', array('target'=>'_blank')) ?>

Yii与您的问题没有任何关系。你们不知道绝对URL和相对URL的区别

在代码中,任何地方都不使用Yii。Yii有一个功能强大的URL管理器,它包含以下方法:createUrl、createAbsoluteUrl和其他。你不用这个


你需要理解绝对URL和相对URL的区别,然后你的问题就消失了。StackOverflow中还有更多信息:

希望所有URL都是外部URL。然后检查您的url中的
http:
。如果url包含http,则直接使用,否则添加

function is_valid_url($url)
{
   if(strpos($url, "http://")!==false)
      return $url; // correct
   else return "http://$url";// http not found.
}
在您的
标签中

<a target="_blank" rel="nofollow" href=<?php echo is_valid_url($r['url']) ;?>>
   VISIT STORE  </a>


您提供的链接无法解决我的问题。如果你回答的话,请贴上密码。请注意你说话的方式。我无法控制url。它来自一个API。它创建的url形式为http://http//google.com,我添加了空格,因为我正在将它转换为一个链接。你可以这样使用它:
echo-CHtml::link('google'),(strpos($r['url'],'www')==0)?/。$r['url']:$r['url'],数组('target=>'u blank'))
我也面临着同样的问题。如果你找到了解决方法,请与我分享。
<a target="_blank" rel="nofollow" href=<?php echo is_valid_url($r['url']) ;?>>
   VISIT STORE  </a>