Skip to content

Instantly share code, notes, and snippets.

@BlackScorp
Created August 24, 2019 14:04
Show Gist options
  • Save BlackScorp/5188aa3ad6ab6aab9f706bcb1a031af0 to your computer and use it in GitHub Desktop.
Save BlackScorp/5188aa3ad6ab6aab9f706bcb1a031af0 to your computer and use it in GitHub Desktop.
Code for the Video https://youtu.be/Hx83NJDzbj4
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
function render(string $path,array $data){
if(!is_file($path)){
trigger_error('Datei "'.$path.'" wurde nicht gefunden');
return null;
}
extract($data,EXTR_SKIP);
ob_start();
require_once $path;
$content = ob_get_clean();
return $content;
}
function escape(string $data){
return htmlspecialchars($data,ENT_QUOTES,'UTF-8');
}
$data =[
'title'=>'Hallo Welt 2',
'seitenName'=>'<i>Youtube</i>'
];
$path = __DIR__.'/templates/main.php';
echo render($path,$data);
<!DOCTYPE>
<html lang="de">
<head>
<title><?= $title ?></title>
<meta charset="utf-8"/>
</head>
<body>
<?php require_once __DIR__.'/header.php'?>
<h1>Willkommen</h1>
<p>Willkommen auf meiner Seite <b><?= escape($seitenName) ?></b></p>
<?php require_once __DIR__.'/footer.php'?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment