Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 726
Eric Avatar asked Jan 27 '26 06:01

Eric


1 Answers

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 // .".";

like image 83
superkayrad Avatar answered Jan 29 '26 19:01

superkayrad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!