PHP Split long string into multiple line

Break string into multiple line

3
1779

To break long string str_split() function can be used in such a way that

<?php
  $text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.";
$char = 55;    
$chunks = str_split($text, $char);
foreach($chunks as $piece){
   echo '<p class="sting-piece">' . $piece. '</p>';  
} 
?>

OUTPUT: 

str_split($text, $char); “str_split” breaks the string into array after count on 55 characters, in loop we are adding custom tag for each line.

3 COMMENTS