pouncer Posted April 5, 2007 Share Posted April 5, 2007 function get_Keyword() { return $this->row['keyword']; } if the keyword is more then 10, i want it to show the first 10 letter with .. on the end of it, otherwise just to return the whole string? e.g keyword = "mr bean excellent DVD" the function should return: mr bean ex.. Link to comment https://forums.phpfreaks.com/topic/45793-function-strlen-question/ Share on other sites More sharing options...
utexas_pjm Posted April 5, 2007 Share Posted April 5, 2007 <?php // ... return (strlen($str) < 10 ? $str : substr($str, 0, 10)); // ... ?> Link to comment https://forums.phpfreaks.com/topic/45793-function-strlen-question/#findComment-222446 Share on other sites More sharing options...
boo_lolly Posted April 5, 2007 Share Posted April 5, 2007 <?php function get_keyWord($string){ if(strlen($string) > 10){ $string = substr($string, 0, 10) . '...'; } return $string; } get_keyWord($this->row['keyword']); ?> that should work. Link to comment https://forums.phpfreaks.com/topic/45793-function-strlen-question/#findComment-222450 Share on other sites More sharing options...
pouncer Posted April 5, 2007 Author Share Posted April 5, 2007 they didn't work guys, any ideas peeps? Link to comment https://forums.phpfreaks.com/topic/45793-function-strlen-question/#findComment-222479 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 How didn't it work? Please give us a hint. Ken Link to comment https://forums.phpfreaks.com/topic/45793-function-strlen-question/#findComment-222498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.