utoronto / email-merge
电子邮件合并操作的令牌插值
0.0.3
2017-01-02 16:32 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2024-09-29 01:22:47 UTC
README
PHP组件,用于处理带有占位符令牌的电子邮件模板。假设电子邮件模板可由用户编辑。创建新模板需要声明允许的占位符令牌集。如果模板文本包含看起来像令牌但实际上不是期望的项,将抛出异常。
基本用法
// Define allowed token names $tokens = new TokenSet(array("USERNAME", "FOO", "BAR")); // Email subject line may contain tokens also $subject = "Hello %USERNAME%"; // HTML email body $htmlBody = <<<HTML_BODY <p>Here is a list of interpolated values <ul> <li>Foo: %FOO%</li> <li>Bar: %BAR%</li> </ul> </p> HTML_BODY; // Create a template in which all tokens must be "allowed" $tpl = new Template($subject, $htmlBody, $tokens); $parser = new Parser($tpl); $data = array( "USERNAME" => "qq12345", "FOO" => "my foo value", "BAR" => "my bar value" ); // A Parser instance will return Template objects containing interpolated values $result = $parser->getResult($data);
意外的令牌
// Define allowed token names $tokens = new TokenSet(array("USERNAME", "FOO", "BAR")); // token name not in allowed set $subject = "Hello %NOT_A_LEGAL_TOKEN%"; // throws UnrecognizedTokenException $tpl = new Template($subject, "", $tokens);