开发者

PHP regex with for double bracket keyword

开发者 https://www.devze.com 2023-03-20 00:01 出处:网络
In PHP, how would one search search for a double bracketed keyword (ie. [[keyword]]) and replace it with an php include when found?

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

精彩评论

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