Here is completed code. Run it.
Example:
PHP
<?php
// Horje.Com
$stringSentence = 'PHP What is the best way to get the first 5 words of a str?';
$stringSentence = preg_replace('/\s+/', ' ', $stringSentence);
$buffer = '';
$count = 1;
$length = strlen($stringSentence);
for ($i = 0; $i < $length; $i++) { if ($stringSentence[$i] !== ' ') { $buffer .= $stringSentence[$i]; } else {
//echo ' '.$count++.' '.$buffer.'</br>';
$pieces = explode(" ", $stringSentence);
$first_part = implode(" ", array_splice($pieces, 0, $count++));
echo ''.$first_part.'</br>'; $buffer = ''; }
}
$pieces = explode(" ", $stringSentence);
$first_part = implode(" ", array_splice($pieces, 0, $count++));
echo ''.$first_part.'';
?>
How to extract from big line to small line one by one from a Sentence | PHP Extract Tutorial |
How to extract from small line to big line one by one from a Sentence | PHP Extract Tutorial |
How to extract Domain Name from Full URL in PHP | PHP Extract Tutorial |
How to extract only name from domain in PHP | PHP Extract Tutorial |
How to extract All url from a single page by PHP | PHP Extract Tutorial |
How to get first Five Line from CSV File | PHP Extract Tutorial |
How to get first 100 records from a csv file in PHP | PHP Extract Tutorial |
How to get meta Tag | PHP Extract Tutorial |
How to get title description image and multiple images from URL | PHP Extract Tutorial |
How to read a txt file from a zip remote URL | PHP Extract Tutorial |
How to extract all url from a html single page in PHP | PHP Extract Tutorial |
How to extract string one by one from sentence from Upper to lower in PHP | PHP Extract Tutorial |
Type
: |
php |
Category
: |
Web Tutorial |
Sub Category
: |
PHP Extract Tutorial |
Uploaded by
: |
Admin |