Was*_*eem 3 php string hyperlink
我想要这样的东西
用户输入网站链接
如果链接没有以"http://"开头,我需要检查链接我想在链接上附加"http://".
我怎么能用PHP做到这一点?
Tom*_*igh 11
if (stripos($url, 'http://') !== 0) {
$url = 'http://' . $url;
}
Run Code Online (Sandbox Code Playgroud)
我会建议稍微改进汤姆的
Run Code Online (Sandbox Code Playgroud)if (0 !== stripos($url, 'http://') && 0 !== stripos($url, 'https://')) { $url = 'http://' . $url; }
但是,这会弄乱使用其他协议的链接(ftp:// svn:// gopher:// etc)
| 归档时间: |
|
| 查看次数: |
6091 次 |
| 最近记录: |