开发者

Filter only shortcode from a post

I am using a contact page plugin for my blog.The shortcode using for this is [my-shortcode]. Is ther开发者_JS百科e anyways to filter only the shortcode from the content. Eg: Test post [my-shortcode] Demo widget.here i need to filter only the shortcode.Thank you


You can use regex to get the value of brackets within a string like so.

if(preg_match_all('/\[(.*?)\]/',$_POST['my_key'],$matches))
{
    foreach($matches as $match)
    {
        if($match[1] == 'my-short-code')
        {
            //Do whetever
            break 2;
        }
    }
}

Note: match[1] may be match[0]

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜