【发布时间】:2014-01-19 18:08:12
【问题描述】:
我正在尝试将 http:// 放在一个字符串上,如果它不包含它,然后忽略该字符串,如果它已经存在问题是它没有忽略字符串如果确实包含它,这是我的代码:
if(strpos($_POST['test-website'], "http://") === false || strpos($_POST['test-website'], "https://") === false){
$url = "http://".$_POST['test-website'];
}else
$url = $_POST['test-website'];
//Value: test.com
//Result: http://test.com
//Value: http://test.com
//Result: http://http://test.com
//Value: https://test.com
//Result: http://https://test.com
【问题讨论】:
-
strpos 返回一个数字或 false。从来都不是真的。
-
无论这是一个错字,使用
||而不是|(逻辑和按位运算)
标签: php string boolean href strpos