Skip to content

Instantly share code, notes, and snippets.

@enderandpeter
Last active January 2, 2016 20:29
Show Gist options
  • Save enderandpeter/8356802 to your computer and use it in GitHub Desktop.
Save enderandpeter/8356802 to your computer and use it in GitHub Desktop.
Split on linebreaks and a delimiter on each line.
<?php
$thestring =<<< EOS
The beats: fast
The rhymes: bold
The brass: monkey
EOS;
// If this doesn't work, try the pattern /$\R?^/m
// Yes, that's the endline before the startline.
foreach(preg_split("/\r\n|\n|\r/", $thestring) as $line){
$linearray = explode(':', $line);
echo '<b>' . $linearray[0] . '</b>: ' . $linearray[1] . '<br />';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment