Mega Code Archive

 
Categories / Php / Code Snippets
 

Splitting a string

<?php //using the split function //our string $msg1 = "This is a string with spaces between it"; //the pattern $pattern = " "; //store in the array $splitstring $splitstring = split($pattern , $msg1); //loop through all items in the array foreach ($splitstring as $value) echo "$value<br>"; //display one of the items in the array echo "$splitstring[0]"; ?>