Konstantinos-infogeek
8/19/2012 - 8:32 PM

PHP

PHP

<!DOCTYPE HTML>
<html>
<head>
		<meta lang="en" charset="utf8" />
		<meta name="author" content="Konstantinos Tsatsarounos" />

		<!-- CSS -->
		<style type="text/css">
			h1 {
				font-family: arial;
				font-weight: bold;
				color: #444;
				width: 200px;
				font-size: 20px;
				text-align: center;
			}

			.box {
				font-family: consolas;
				font-size: 15px;
				color: #000;
				width: 200px;
				background-color: #fff;
				border: 1px solid #444;
				box-shadow: 0 0 3px #333;
				padding: 10px 20px;
				border-radius: 3px;
				margin: 5px 0 0 0;
			}
		</style>
		<!-- CSS end -->
	<title>PAGE TITLE</title>
</head>
<body>
	<?php
//html template in a variable
		$template = "
		<div class='box'>
		<h1>[NAME]</h1>
		<hr />
		<p class='[paragraph]' >[TEXT]</p>
		</div>
		";

//Data selection Object
		$DataObject = [
			"NAME" => ["First Paragraph", "Second Paragraph","Third Paragraph"], 
			"CLASS" => ["prgr", "prgr", "prgr"],
			"TEXT" => ["text for the first paragraph", "text for the second paragraph", "finally i succeeded to create a php template"] 
			];
//Set a loop to combine template and Data!
		for( $i = 0 ; $i < count( $DataObject["NAME"]); $i++){
			$temp = $template;
			$temp = str_replace("[NAME]", $DataObject["NAME"][$i], $temp);
			$temp = str_replace("[paragraph]", $DataObject["CLASS"][$i], $temp);
			$temp = str_replace("[TEXT]", $DataObject["TEXT"][$i], $temp);
			echo $temp;
		}
			
	 ?>

</body>
</html>