我在做什么错在这里家伙?
$string = "string How Long is a Piece of String?";
if $string = <5;
{
echo "string is less than 5";
}
else
{
echo "string is more than 5";
}
我在做什么错在这里家伙?
$string = "string How Long is a Piece of String?";
if $string = <5;
{
echo "string is less than 5";
}
else
{
echo "string is more than 5";
}
1,条件在括号内。
2,你不需要;在一个条件之后。
3,小于根本不< = <除非你想回声“字符串是小于或等于小于5”
$string = "string How Long is a Piece of String?";
if (strlen($string) < 5)
{
echo "string is less than 5";
}
else
{
echo "string is more than 5";
}
缺少括号,如果周围的声明,任何需要分号?也小于或等于按错误顺序的运营商。应该是这样的:
if($ string < = 5) { echo“string is less than 5”; }
其他指出语法错误,实际的比较你需要使用strlen
函数的字符串的长度:
$string = "string How Long is a Piece of String?";
if (strlen($string) < 5)
{
echo "string is less than 5";
}
else
{
echo "string is more than 5";
}
lmao,我忘了明显的strlen。有时当答案如此简单时,你会忘记明显的。 – HoLyVieR 2010-06-05 01:18:53
可能是你正在寻找的strlen()功能?
类型杂耍名曰:
http://nl2.php.net/manual/en/language.types.type-juggling.php
$string = "string How Long is a Piece of String?";
if ($string < 5)
字符串转换为INT,变为0
if (0 < 5)
真!
strlen
/mbstrlen
是可能的候选人你寻找热塑成型的
但是,这不是问题,有obivously更多的事情错误的代码:)
还要注意,如果该字符串具有多它将返回一个错误的字符数,但是一个字节数。
您可能需要知道这一点的轨道:)现在,您的语法顶部。
这么多事情.. – 2010-06-05 01:19:19
哈哈哈喜欢这些回复,来吧伙计们我是新来的..真的很享受学习PHP的惊人的多少我每天学习..感谢您的帮助 – Webby 2010-06-05 01:27:35
我会upvoted如果它是'if $ string = <3'。 – 2010-06-05 01:40:23