joyinc Posted February 15, 2010 Share Posted February 15, 2010 Hey Guys PHP newbie here. I have the following PHP code that generated and prints HTML. <?php function checkPath() { $directoryUrl = ($_GET['path'] == "" ? "audio_files/voices/female/" : $_GET['path']); return $directoryUrl; } function genList() { $excludes = array(".","..",".DS_Store",".svn"); $directoryUrl = checkPath(); $itemList = scandir($directoryUrl) or die("Unable to Access $directoryUrl"); foreach ($itemList as $item) { if (!in_array("$item", $excludes)) { print " <li class='sample_li'> <h2>$item</h2> <ul> <li> <span class='label'>Select a sample: </span> </li>"; $subDirectory = $directoryUrl.$item; $subItemList = scandir($subDirectory) or die("Unable to Access $subDirectory"); foreach ($subItemList as $subItem) { if (!in_array("$subItem", $excludes)) { $file = str_replace(".mp3", "", $subItem); print " <li> <a href='#' id='track-0'>$file</a> </li>"; } } print " </ul> <p> <span class='label'>Now Playing:</span> <span class='now_playing' id='trackname'>Relaxed</span> <span class='pcent' id='pcent'>37%</span> </p> <ul class='controls'> <li> <a href='#' id='play'>Play</a> </li> <li> <a href='#' id='pause'>Pause</a> </li> <li> <span> ~ </span> <a href='#' id='stop'>Stop</a> </li> <li> <span> ~ </span> <a href='#' id='download'>Download</a> </li> </ul> </li>"; } } } ?> However I feel that it would be cleaner if the function and the markup were separate however I am not sure how to do this given the nature of the function structure. Any help would be really appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/192171-help-with-separating-function-and-markup/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.