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.
}
}
精彩评论