[英]PHP if statement with strlen (not working as expected)
<?php if(strlen($r['body'] <= '74')): ?>
<?php echo $r['body']; ?>
<?php else: ?>
<?php echo substr($r['body'], 0, 74) ."..."; ?>
<?php endif; ?>
when $r['body']
== more than 74 chars everything works as expected but as soon as $r['body']
== less than 74 chars it still attaches "..." 当$r['body']
==大于74个字符时,一切正常,但是$r['body']
==小于74个字符时,它仍然附加“ ...”
I can work out what i have been doing wrong? 我可以找出我做错了什么吗?
您没有关闭正确的strlen,也是74是一个不应在引号内的整数试试:
if(strlen($r['body']) <= 74):
Try this 尝试这个
<?php if(strlen($r['body']) <= 74 ): ?>
strlen()
return the length of string which you can test in if
strlen()
返回字符串的长度,你可以测试if
you have the parenthesis in the wrong place. 您将括号放在错误的位置。 try this: 尝试这个:
<?php if(strlen($r['body']) <= '74'): ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.