Check string length in PHP

前端 未结 7 1726
渐次进展
渐次进展 2020-11-28 14:28

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.

7条回答
  •  渐次进展
    2020-11-28 14:39

    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.";
       }
    }
    

提交回复
热议问题