开发者

What causes substr to fail?

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($开发者_StackOverflow中文版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 "/"


The comparison operator is ==, not =:

if ($m == "/") {
     echo $string;
}


Shouldn't that be == rather than =?


if ($m = "/") {

You are assigning the value "/" to $m and that evaluation returns true. You want to compare and should use

if ($m == "/") {
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜