onedumbcoder Posted June 24, 2009 Share Posted June 24, 2009 is this a bad idea $e = substr($post['title'], 0, 40); if there is a chance that title might be less the 40chars long? lets say the title is only 4 chars long, will it add 36 empty spaces? or am i fine using that. Thank you and as always appreciate the help. Link to comment https://forums.phpfreaks.com/topic/163452-solved-is-this-a-bad-idea-e-substrposttitle-0-40-if-there-is-a-chance/ Share on other sites More sharing options...
vbnullchar Posted June 24, 2009 Share Posted June 24, 2009 check: http://us3.php.net/manual/en/function.str-pad.php Link to comment https://forums.phpfreaks.com/topic/163452-solved-is-this-a-bad-idea-e-substrposttitle-0-40-if-there-is-a-chance/#findComment-862446 Share on other sites More sharing options...
pkedpker Posted June 24, 2009 Share Posted June 24, 2009 is this a bad idea $e = substr($post['title'], 0, 40); if there is a chance that title might be less the 40chars long? lets say the title is only 4 chars long, will it add 36 empty spaces? or am i fine using that. Thank you and as always appreciate the help. <?php $sizeOfe = $strlen($e); $e = substr($post['title'], 0, sizeOfe < 40 ? sizeOfe : 40); ?> Link to comment https://forums.phpfreaks.com/topic/163452-solved-is-this-a-bad-idea-e-substrposttitle-0-40-if-there-is-a-chance/#findComment-862455 Share on other sites More sharing options...
akitchin Posted June 24, 2009 Share Posted June 24, 2009 i don't suppose you've thought about passing it a test string to see? substr() won't pad the string; if the length is longer than the string, it will simply return the string. Link to comment https://forums.phpfreaks.com/topic/163452-solved-is-this-a-bad-idea-e-substrposttitle-0-40-if-there-is-a-chance/#findComment-862460 Share on other sites More sharing options...
onedumbcoder Posted June 24, 2009 Author Share Posted June 24, 2009 thanks Link to comment https://forums.phpfreaks.com/topic/163452-solved-is-this-a-bad-idea-e-substrposttitle-0-40-if-there-is-a-chance/#findComment-862481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.