Search code examples
phpspecial-charactersexplode

PHP Explode Show Seperator


So I wrote the following code to show the words after the fourth full stop / period in a sentence.

$text = "this.is.the.message.seperated.with.full.stops.";
$limit = 4;

   $minText = explode(".", $text);

   for($i = $limit; $i < count($minText); $i++){
       echo $minText[$i];
   }

The algorithm is working and it is showing me the rest of the sentence after the fourth "." full stop / period.... My problem is that the output is not showing the full stops in the sentence therefore it is showing me just text without the proper punctuation "." .... Can someone please help me out on how to fix the code to display also the full stops / periods ??

Thanks a lot


Solution

  • you could try this...

        for($i = $limit; $i < count($minText); $i++){
           echo $minText[$i].".";
       }
    

    notice the added period at the end of the echo command // .".";