丢失时向URL添加http://前缀 [英] Add http:// prefix to URL when missing
本文介绍了丢失时向URL添加http://前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我有一个非常简单的代码
< a href ='。$ aProfileInfo ['Website']。 'target =_ self>
< div class =callButton>网站< / div>
< / a>
问题是,如果用户没有输入http://,那么链接会指向我的网站,而不是外部网站,因为它应该。
如果用户没有输入http://,如何在PHP中检查并在没有时自动添加解决方案
解决方案一个简单的解决方案可能无法在所有情况下工作(即'https://'):
if(strpos($ aProfileInfo ['Website'],'http://')=== false){
$ aProfileInfo ['Website'] ='http://'.$aProfileInfo ['Website'];
}
Hello I have a very simple code
<a href="'.$aProfileInfo['Website'].'" target="_self">
<div class="callButton">Website</div>
</a>
The problem is that if the user does not enter http:// the link will then point to my website and not to the external website as it should.
How do I check in PHP if the user has not entered http:// and automatically add it when it is not there?
解决方案
A simple solution which may not work in all cases (i.e. 'https://'):
if (strpos($aProfileInfo['Website'],'http://') === false){
$aProfileInfo['Website'] = 'http://'.$aProfileInfo['Website'];
}
这篇关于丢失时向URL添加http://前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文