I have a string that is 141 characters in length. Using the following code I have an if
statement to return a message if the string is greater or less than 140.
$message
is propably not a string at all, but an array. Use $message[0]
to access the first element.
The xpath() function does not return a string. It returns an array with XML elements (of type SimpleXMLElement), which may be casted to a string.
if (count($message)) {
if (strlen((string)$message[0]) < 141) {
echo "There Are No Contests.";
}
else if(strlen((string)$message[0]) > 142) {
echo "There is One Active Contest.";
}
}
[0]=> string(141)
means that $message is an array, not string, and $message[0] is a string with 141 characters in length.
[0]=> string(141)
means $message is an array so you should do strlen($message[0]) < 141
...
Because $xml->xpath always return an array, and strlen
expects a string.
Try the common syntax instead:
if (strlen($message)<140) {
echo "less than 140";
}
else
if (strlen($message)>140) {
echo "more than 140";
}
else {
echo "exactly 140";
}