PX : code

Limit words from long string by Johan Yusoff bin Abu Bakar
Download this code


<?
        $str="The is a verrrrrrryyyyy long string. The is a verrrrrrryyyyy long string.";    //The string
        $no_of_words = 7;                                       // no. of words to appear
        $str_array = split(" ",$str,$no_of_words+1);            // split strings into array element
        if(count($str_array)>$no_of_words) {                    // check no of words from original string
                for($i=0; $i < $no_of_words; $i++) {            // if it is longer than what we want, 
                        print $str_array[$i]." "; }             //       print word by word
                print "<b>...........(more)</b>";}              //       print .....
        else {                                                  // otherwise
                print $str; }                                   //       print the whole string

?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.