是什么原因导致 substr 失败?
简单的 substr 调用无法正常运行。我只想抓取以正斜杠结尾的字符串。这里有七个字符串。
HELLO/NN, SMILE/JJ, JUMP/, GOOD/RB, GREAT/JJ, HAPPY/NNP, SEAPORT/
$m = substr($string, -1);
if ($m = "/") {
echo $string;
}
这段代码每次都会以某种方式返回 true。七个字全部打印出来。 我尝试过 strrev 和许多其他字符串函数。似乎没有 事情。我可以从字面上打印 $m 并看到它是“/”,但是 if 语句 确定每个单词都满足 $m = "/" 标准。即使 $m 不是“/”
A simple substr call is not functioning properly. I want to grab only the strings which end with a forward slash. Here are seven strings.
HELLO/NN, SMILE/JJ, JUMP/, GOOD/RB, GREAT/JJ, HAPPY/NNP, SEAPORT/
$m = substr($string, -1);
if ($m = "/") {
echo $string;
}
This code somehow returns true every time. All seven words are printed.
I've tried strrev and many other string functions. It doesn't seem to
matter. I can literally print $m and see that it's "/" but the if statement
decides that every word meets the $m = "/" criteria. Even when $m is not a "/"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
比较运算符是
==
,而不是=
:The comparison operator is
==
, not=
:难道不应该是
==
而不是=
吗?Shouldn't that be
==
rather than=
?您将值“/”分配给 $m 并且该评估返回 true。您想要比较并且应该使用
You are assigning the value "/" to $m and that evaluation returns true. You want to compare and should use