Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
<?php
error_reporting(E_ALL);
$str = 'test.php';
$str = 'Hey, ein include säh so aus: {include file="test.php"}... Und hier wäre ein 2. Include {include file="test.php"}';
$replace = preg_replace('/{include file=\"(.+?)\"}/e', "file_get_contents('\\1')", $str);
echo $replace;
?>
<?php
error_reporting(E_ALL);
$books['titel'] = 'Hallo';
$books['autor'] = 'David';
$str = 'Hallo <br />
{foreach $books AS $select}
{$titel}
{/foreach}';
$search = '/{foreach (.*?) AS (.*?)}/isUe';
$replace = "foreach(\\1 AS \\ \\2)
{
echo \\3
}";
echo preg_replace($search, $replace, $str);
?>
<html>
<head>
<title><?php echo $this->title; ?></title>
</head>
<body>
<table>
<?php foreach($this->books as $book): ?>
<tr>
<td><?php echo $book['titel'] . ' - ' . $book['autor']; ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>
<?php
class Template
{
protected $_templateFile;
protected $_vars = array();
public function __construct($templateFile)
{
if(!file_exists("{$templateFile}.php"))
{
throw new InvalidArgumentException('Template file not found');
}
$this->_templateFile = $templateFile;
}
public function assign($var, $value)
{
if(isset($this->_vars[$var]))
{
throw new InvalidArgumentException('Variable has already been set');
}
$this->_vars[$var] = $value;
}
public function render()
{
ob_start();
include_once("view/{$this->_templateFile}.php");
$data = ob_get_clean();
ob_end_clean();
return $data;
}
public function __get($var)
{
return isset($this->_vars[$var]) ? $this->_vars[$var] : '';
}
}
$tpl = new Template("template");
$books = array(array('titel' => 'Buch1', 'autor' => 'Autor1'), array('titel' => 'Buch2', 'autor' => 'Autor2'));
$tpl->assign('books', $books);
echo $tpl->render();
?>