문제

I want to clean the url addres but first I want to check if what should be replace is in the string. I want to use strpos because is faster, but it fails to detect the string.

$txt = 'http://www.youtube.com/watch?v=aWFmXFFjJfw';

if(strpos($txt, 'http://www.')){
echo 'true strpos'; // not shows
}

if(strstr($txt, 'http://www.')){
echo 'true strstr'; // show
}

Also

$match = strpos($txt, 'http://www.');
var_dump($match); // int(0);
도움이 되었습니까?

해결책

Because it equals 0 which equates to false.

Instead use:

if(strpos($txt, 'http://www.')!==false){
    echo 'true strpos'; //shows
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top