Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i need a little help to with this issue:

I have a string wich contains shortcodes like [shortcode data="1" data2="2"] How I can extract with regex? without wordpress system?

Thanks in advance.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Where is this string located ? I know you wrote "without wordpress system" , but WordPress has a function get shortcode regex

If you really want to avoid it for some reason, the following example might help you :

// check the post for a short code 
function check_shortcode( $shortcode = NULL ) {

    $post_to_check = get_post( get_the_ID() );

    // Until we search, set false 
    $found = false;

    //  no short - FALSE
    if ( ! $shortcode ) {
        return $found;
    }

    // check the post content for the short code 
    if ( stripos( $post_to_check->post_content, '[' . $shortcode) !== FALSE ) {
        // we have found the short code
        $found = TRUE;
    }

    // return our final results 
    return $found;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.