AKalair Posted April 4, 2009 Share Posted April 4, 2009 Hiya, Im trying to check the length of this string is between 1 and 5 characters. But when I run this I get this error message. "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /www/001webs.com/p/h/p/phpforum91/htdocs/time.php on line 7" <?php $abcd = 'abcd'; $Length = strlen("$abcd"); if ($strlen '>0' && '6<' ) { echo "$Length"; } else {echo "too long"; } ?> Any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/152589-checking-the-length-of-a-string/ Share on other sites More sharing options...
nrg_alpha Posted April 4, 2009 Share Posted April 4, 2009 You are checking the length of $strlen (which isn't declared).. I think you want to check using $length.. $abcd = 'abcd'; $length = strlen($abcd); echo ($length > 0 and $length < 6)? $length : 'too long'; Link to comment https://forums.phpfreaks.com/topic/152589-checking-the-length-of-a-string/#findComment-801401 Share on other sites More sharing options...
AKalair Posted April 4, 2009 Author Share Posted April 4, 2009 Thank You ! That was a silly thing to do, doh! I'm using it to check user input on a form. What else do I need to consider, I'm looking into htmlspecialchar now. Link to comment https://forums.phpfreaks.com/topic/152589-checking-the-length-of-a-string/#findComment-801402 Share on other sites More sharing options...
jjacquay712 Posted April 5, 2009 Share Posted April 5, 2009 D00d wtf are you doing?!?! your putting variables inside of strings for no reason. Link to comment https://forums.phpfreaks.com/topic/152589-checking-the-length-of-a-string/#findComment-801532 Share on other sites More sharing options...
nrg_alpha Posted April 5, 2009 Share Posted April 5, 2009 I'm not sure I follow.. who's snippet are you referring to? Link to comment https://forums.phpfreaks.com/topic/152589-checking-the-length-of-a-string/#findComment-801533 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.