如果字符串不包含http://,则在该字符串上放置http://否则在php中忽略该字符串

如果字符串不包含http://,则在该字符串上放置http://否则在php中忽略该字符串,php,string,boolean,href,strpos,Php,String,Boolean,Href,Strpos,我试图在一个字符串上放置一个http://,如果它不包含该字符串,则忽略该字符串,如果它已经包含该字符串,则忽略该字符串。问题是,如果它确实包含该字符串,则不忽略该字符串,以下是我的代码: 您应该使用==false而不是!==true,strpos将永远不会返回true if(strpos($_POST['test-website'], "http://") === false || strpos($_POST['test-website'], "https://") === false) {

我试图在一个字符串上放置一个http://,如果它不包含该字符串,则忽略该字符串,如果它已经包含该字符串,则忽略该字符串。问题是,如果它确实包含该字符串,则不忽略该字符串,以下是我的代码:


您应该使用
==false
而不是
!==true
strpos
将永远不会返回
true

if(strpos($_POST['test-website'], "http://") === false || strpos($_POST['test-website'], "https://") === false) {

您应该使用
==false
而不是
!==true
strpos
将永远不会返回
true

if(strpos($_POST['test-website'], "http://") === false || strpos($_POST['test-website'], "https://") === false) {
strpos()返回针相对于的位置 干草堆字符串的开头(与偏移无关)。退换商品 如果没有找到指针,则为FALSE。它不会返回true

strpos()返回针相对于的位置 干草堆字符串的开头(与偏移无关)。退换商品 如果没有找到指针,则为FALSE。它不会返回true


strpos返回一个数字或false。从不为true。无论这是打字错误,请使用
| |
而不是
|
(逻辑和按位操作)strpos返回数字或false。从不为true。无论这是一个打字错误,请使用
| |
而不是
|
(逻辑和按位操作)//Value:test.com结果://Value:Result://Value:test.com结果://Value:Result://Value:Result:Result:Result:
if(strpos($_POST['test-website'], "http://") === false || strpos($_POST['test-website'], "https://") === false