Jump to content

explode a "." but ignore "Dr."


kevin_newbie

Recommended Posts

You would set the result of the function to a variable, eg;

 

$Result = advanced_index($skipped,$Sentence);
$number_of_sentences_wanted = 2;

// Then loop and echo the amount of sentences you want
For($i=0;$i<$number_of_sentences_wanted;$i++){
   echo($Result[$i]);
}

 

Though i would assume you want to limit length also;

$Result = advanced_index($skipped,$Sentence);
$number_of_characters_wanted = 30;

// Then loop and echo the amount of sentences you want
$word_array = array();
$characters = 0;
Foreach($Result As $item){
   $words = explode(" ",$item);
   for($i=0;$i<count($words);$i++){
      // The 3 is for the 3 dots added.
      if((strlen($words[$i]) + $characters + 3) > $number_of_characters_wanted){
         $word_array[] = "...";
         break;
      }else{
         $characters += strlen($words[$i]);
         $word_array[] = $words[$i];
      }
   }
}
echo(implode(" ",$word_array));

 

-cb-

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.