PHP - 极轻的模板系统 [英] PHP - Extremely light templating system

查看:18
本文介绍了PHP - 极轻的模板系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道一个非常简单的php模板系统,就像str_replace("{variable}", $variable);一样简单?

does anyone know a php templating system that is very simple, something like almost as simple as str_replace("{variable}", $variable); ?

我需要在管理面板中的一系列文本区域使用它,站点管理员应该在其中更改网站各种元素的模板(不是页面等复杂的东西,只是内容块)

I need this for a series of textareas in the administration panel, where the site admin should change templates for various elements of the website (not complex stuff like pages etc, just blocks of content)

推荐答案

/**
 * Renders a single line. Looks for {{ var }}
 *
 * @param string $string
 * @param array $parameters
 *
 * @return string
 */
function renderString($string, array $parameters)
{
    $replacer = function ($match) use ($parameters)
    {
        return isset($parameters[$match[1]]) ? $parameters[$match[1]] : $match[0];
    };

    return preg_replace_callback('/{{\s*(.+?)\s*}}/', $replacer, $string);
}

这篇关于PHP - 极轻的模板系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆