开发者

PHP regex with for double bracket keyword

In PHP, how would one search search for a double bracketed keyword (ie. [[keyword]]) and replace it with an php include when found?

My intention is a back-end user will have an basic editor in a textarea in which they can call upon php includes I have predefined via the double bracketed tag th开发者_StackOverflow社区at will render a specific include upon output to the public facing side of the app..


preg_replace_callback() will help you do this with ease. Be careful about the security implications


preg_match is one method, here's how it might work:

if( preg_match( '#\[\[(\w+)\]\]#g', $input, $matches ) )
{
    foreach( $matches as $match )
    {
        // test match, include it if necessary.
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜