Skip to content

Instantly share code, notes, and snippets.

@ilhamarrouf
Created August 29, 2019 08:16
Show Gist options
  • Select an option

  • Save ilhamarrouf/066b5725032ff243d5b7a8e12eeb4ecd to your computer and use it in GitHub Desktop.

Select an option

Save ilhamarrouf/066b5725032ff243d5b7a8e12eeb4ecd to your computer and use it in GitHub Desktop.
Simple PHP Template Parsing
<?php
class MailTemplateParser
{
protected $_openingTag = '{{';
protected $_closingTag = '}}';
protected $_emailValues;
protected $_emailHtml = <<<HTML
<html>
<body>
<h1>Account Details</h1>
<p>Thank you for registering on our site, your account details are as follows:<br>
Username: {{username}}<br>
Password: {{password}}
</p>
</body>
</html>
HTML;
public function __construct($emailValues)
{
$this->_emailValues = $emailValues;
}
public function output() {
$html = $this->_emailHtml;
foreach ($this->_emailValues as $key => $value) {
$html = str_replace($this->_openingTag . $key . $this->_closingTag, $value, $html);
}
return $html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment