, , , , html- . , html .
function render_php($path)
{
ob_start();
include($path);
$var=ob_get_contents();
ob_end_clean();
return $var;
}
//test.php
<?php for($i = 0; $i<5; $i++):?>
<p><?php echo $i;?></p>
<?php endfor ?>
:
render_php('test.php');
, ( , ..
function render_php($path,array $args){
ob_start();
include($path);
$var=ob_get_contents();
ob_end_clean();
return $var;
}
,
//create your template test.php
<?php for($i = $args['start']; $i<$args['end']; $i++):?>
<p><?php echo $i;?></p>
<?php endfor ?>
$args = array('start' => 0, 'end' => 5);
render_php('test.php', $args);
, , , , , . html, .
.
$article = array(
'title' => 'Some Title',
'subtitle' => 'Some Sub Title',
'body' => 'lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
eu nulla quis ligula ornare ultricies. Vivamus malesuada lectus a mi
auctor pellentesque. Maecenas eu ultricies sapien, ac porta augue. ',
'image' => 'img/some_image.jpg'
);
echo render_php('article.php',array $article);
<!DOCTYPE html>
<html>
<head>
<title><?php echo $article['title']; ?></title>
</head>
<body>
<img src='<?php echo $article['image']; ?>' alt='whatever' >
<h1><?php echo $article['title']; ?></h1>
<h2><?php echo $article['subtitle']; ?></h2>
<p><?php echo $article['body'];?></p>
</body>
</html>