使用preg_split正则表达式获取另一个值


Getting another value with regular expression with preg_split

我被下面的问题困了几个小时。我有我自己的cms,我使用短代码[plugin-pluginname]来激活一个插件。现在我想在该短代码中分配一个组,该短代码后来在包含一次文件中用作查询变量,以选择该特定id。

在那一刻,我得到了下面的代码:
$regex = '~'[plugin-([^]]+)]~';
        $content_one = htmlspecialchars_decode($page['content_one']);
        $parts = preg_split($regex, $content_one, -1, PREG_SPLIT_DELIM_CAPTURE);
        foreach($parts as $k => $v){
            if($k & 1)
                include_once('plugins/'.$v.'/'.$v.'.php');
            else
                echo htmlspecialchars_decode($v);
        }

检查[plugin-testplugin]在哪里(以testplugin为例),并包含该特定文件。现在我想写这样的东西[plugin-testplugin 2],其中不仅上述代码仍然有效,当然,而且该数字存储在一个变量中,可以使用查询SELECT * FROM 'database' WHERE 'group' = "'.$var_from_shortcode.'"

欢迎任何帮助和答案来处理和解决这个问题!

你可以使用这个正则表达式然后保存组1值在一个变量?

'[plugin-[A-Za-z ]*('d+)?']

或者使用这个正则表达式找到[plugin-testplugin 2],然后使用'd*找到其中的数字?