Jump to content

Help with Separating Function and Markup


joyinc

Recommended Posts

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 ^_^

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.