yyx748 Posted June 15, 2009 Share Posted June 15, 2009 Original text: "Hello World" ==CASE 1== Turning extra alphabets after position 7 to "..." output: "Hello W..." ==CASE 2== Showing WORDS that comes before position 7. output: "Hello..." Could someone tell me what functions do i use for both cases? Link to comment https://forums.phpfreaks.com/topic/162215-what-php-string-function-should-i-use/ Share on other sites More sharing options...
trq Posted June 15, 2009 Share Posted June 15, 2009 substr Link to comment https://forums.phpfreaks.com/topic/162215-what-php-string-function-should-i-use/#findComment-856078 Share on other sites More sharing options...
joshgarrod Posted June 15, 2009 Share Posted June 15, 2009 I use the following: <?php $count = 10; $words = "blah blah blah"; $shortwords = substr($words,0,$count); echo "$shortwords..."; ?> Giving the output: blah blah ... Obviously change $count to set the character limit. Link to comment https://forums.phpfreaks.com/topic/162215-what-php-string-function-should-i-use/#findComment-856079 Share on other sites More sharing options...
Andy-H Posted June 15, 2009 Share Posted June 15, 2009 $word = "Hello world"; $word = explode (" ", $word); if ( count($word) > 0) { echo $word[0] . '...'; } Link to comment https://forums.phpfreaks.com/topic/162215-what-php-string-function-should-i-use/#findComment-856083 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.