我試圖找到一個字符串是否包含了一定的文本或不使用的strstr()爲什麼這個strstr()返回false?
$t = "http://site.com/image/d2737cda28cb420c972f7a0ce856cf22";
var_dump(strstr('/image/', $t));
exit;
但是這給false
。爲什麼它給予fasle?如何解決它?
我試圖找到一個字符串是否包含了一定的文本或不使用的strstr()爲什麼這個strstr()返回false?
$t = "http://site.com/image/d2737cda28cb420c972f7a0ce856cf22";
var_dump(strstr('/image/', $t));
exit;
但是這給false
。爲什麼它給予fasle?如何解決它?
應與您的增值經銷商使用strpos,更快,更少的資源,從手動
<?php
$t = "http://site.com/image/d2737cda28cb420c972f7a0ce856cf22";
$findme = '/image/';
$pos = strpos($t, $findme);
// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
?>
嘗試這樣反而
<?php
$t = "http://site.com/image/d2737cda28cb420c972f7a0ce856cf22";
var_dump(strstr($t, '/image/'));
exit;
?>
你應該使用strpos,更快,更少的資源 – 2013-08-07 02:25:18
明確的證據表明Jedi寫了php。 「在乾草堆裏,你必須找到一根針。」 – Floris