检查 PHP 中的字符串长度
我有一个长度为141个字符的字符串。使用以下代码,我有一个语句,用于在字符串大于或小于 140 时返回消息。if
libxml_use_internal_errors(TRUE);
$dom = new DOMDocument();
$dom->loadHTMLFile($source);
$xml = simplexml_import_dom($dom);
libxml_use_internal_errors(FALSE);
$message = $xml->xpath("//div[@class='contest']");
if (strlen($message) < 141)
{
echo "There Are No Contests.";
}
elseif(strlen($message) > 142)
{
echo "There is One Active Contest.";
}
我在$message中使用了var_dump,它显示字符串是。这是我的问题:当我将语句的数字更改为 and 时,它仍然返回第一条消息,尽管字符串大于 131。[0]=> string(141)
if
<130
>131
无论我使用什么数字少于141,我总是会得到“没有比赛”的回复。