Apply for Zend Framework Certification Training

Corephp




implode(' ', array_slice(explode(' ', $sentence), 0, 10));

To add support for other word breaks like commas and dashes,
preg_match gives a quick way and doesn't require splitting the string:

function get_words($sentence, $count = 10) {
  preg_match("/(?:w+(?:W+|$)){0,$count}/", $sentence, $matches);
  return $matches[0];
}                                    

< How to count no of elements in array in php How to calculate hours between two dates in php >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top