Php 为什么这个strstr()返回false?
我正在尝试使用strstr()查找字符串是否包含特定文本Php 为什么这个strstr()返回false?,php,strstr,Php,Strstr,我正在尝试使用strstr()查找字符串是否包含特定文本 但这会给出false。为什么它给了法斯?如何修复它?您的参数已反转(请参阅)。这是正确的使用方法: strstr($t, '/image/'); 您的参数是反向的(请参见)。这是正确的使用方法: strstr($t, '/image/'); 您应该更快、更少地使用VAR手册中的资源 <?php $t = "http://site.com/image/d2737cda28cb420c972f7a0ce856cf22"; $find
但这会给出
false
。为什么它给了法斯?如何修复它?您的参数已反转(请参阅)。这是正确的使用方法:
strstr($t, '/image/');
您的参数是反向的(请参见)。这是正确的使用方法:
strstr($t, '/image/');
您应该更快、更少地使用VAR手册中的资源
<?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";
}
?>
您应该将手册中的资源更快、更少地用于VAR
<?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;
?>
试试这样
<?php
$t = "http://site.com/image/d2737cda28cb420c972f7a0ce856cf22";
var_dump(strstr($t, '/image/'));
exit;
?>
您可以查看该函数的文档
验证语法
正确的用法是:var_dump(strstrstr($t,“/image/”) 您可以查看该函数的文档
验证语法
正确的用法是:var_dump(strstrstr($t,“/image/”) 你应该使用strpos,更快,更少的资源一个绝地武士编写php的清晰证据。“大海捞针。”你应该使用strpos,更快,更少的资源——绝地武士编写php的清晰证据。“大海捞针”哦。。。为什么php总是与针头
和干草堆
混在一起?哦。。。为什么php总是与needle
和haystack
混在一起?如果(!$pos)
,就怎么样?我接受了另一个答案,因为这就是我问题的答案。但我正在使用你的解决方案+1没有要点!我失去的所有可爱的点:--开玩笑很好;-)如果(!$pos)
,那就怎么样?我接受了另一个答案,因为这就是我问题的答案。但我正在使用你的解决方案+1没有要点!我失去的所有可爱的点:--开玩笑很好;-)