tags:

views:

17

answers:

1

Hi, I am using a contact page plugin for my blog.The shortcode using for this is [my-shortcode]. Is there 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

A: 

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]

RobertPitt
thank you so much
Guest Visitor