Created
November 7, 2011 02:09
-
-
Save niczak/1344041 to your computer and use it in GitHub Desktop.
String Split Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
This is a simple example of how str_split() works. | |
Written: 11/06/2011, Nicholas Kreidberg | |
Revised: 11/06/2011, Nicholas Kreidberg | |
*/ | |
$description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam molestie tristique lectus in imperdiet. In libero nisi, semper viverra molestie id, ultricies sit amet diam. Etiam in tellus sed risus viverra vulputate in vitae quam. Aenean elementum."; | |
$a = str_split($description); | |
$i = 0; | |
$output = ""; | |
foreach($a as $s) | |
{ | |
// store value in new variable | |
$output .= $s; | |
// check iteration value, essentially | |
// string length in this case | |
if($i == 95) | |
{ | |
// concat break tag on to string | |
$output .= "<br />"; | |
// reset counter | |
$i = 0; | |
} | |
// increment counter | |
$i++; | |
} | |
// display output | |
printf("%s\n", $output); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment