Skip to content

Instantly share code, notes, and snippets.

@k-holy
Created March 22, 2012 09:50
Show Gist options
  • Save k-holy/2157414 to your computer and use it in GitHub Desktop.
Save k-holy/2157414 to your computer and use it in GitHub Desktop.
Smarty3で文字列をテンプレートに
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>&lt;Hello X&#039;SS!&gt;</title>
</head>
<body>
<h1>&lt;Hello X&#039;SS!&gt;</h1>
</body>
</html>
<?php
require_once realpath(__DIR__ . '/../vendor/Smarty/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->assign('title', '<Hello X\'SS!>');
echo $smarty->fetch('string:
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>{$title|escape}</title>
</head>
<body>
<h1>{$title|escape}</h1>
</body>
</html>'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment