Skip to content

Instantly share code, notes, and snippets.

@maxkostinevich
Created August 14, 2015 06:43
Show Gist options
  • Save maxkostinevich/79e4782657745ee4a654 to your computer and use it in GitHub Desktop.
Save maxkostinevich/79e4782657745ee4a654 to your computer and use it in GitHub Desktop.
Convert multi-line string to UL-list
<?php
/*
* Convert multi-line string to UL-list
* 1. Explode the multi-line string ($string) into array by the new line symbol ("\n")
* 2. Convert the array back into the string using "implode" function and append the ul and li tags.
*/
function str_to_list($str){
return '<ul><li>' .implode('</li><li>', explode("\n", $str)). '</li></ul>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment