admin管理员组

文章数量:1426810

I have defined quote post format for the theme:

// Add post-formats for theme
add_theme_support( 'post-formats', array(
        'quote',
) );

After it, I want to display quote from the content. For that, I want to use preg_match_all function to search for <blockquote>Hello World.</blockquote>

if( $format == 'quote' ) {

    $content = apply_filters( 'the_content', get_the_content() );
    preg_match( '/<blockquote.*?>/', $content, $matches );
}

But it is not working. I want to find blockquote tag and display content inside this tag.

I have defined quote post format for the theme:

// Add post-formats for theme
add_theme_support( 'post-formats', array(
        'quote',
) );

After it, I want to display quote from the content. For that, I want to use preg_match_all function to search for <blockquote>Hello World.</blockquote>

if( $format == 'quote' ) {

    $content = apply_filters( 'the_content', get_the_content() );
    preg_match( '/<blockquote.*?>/', $content, $matches );
}

But it is not working. I want to find blockquote tag and display content inside this tag.

Share Improve this question edited May 21, 2019 at 11:56 nmr 4,5672 gold badges17 silver badges25 bronze badges asked May 21, 2019 at 11:39 EGWorldNPEGWorldNP 295 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

Meta-character . match any character except newline. If you have new lines inside quote, try this:

preg_match_all( '#<blockquote.*?>([\s\S]*?)</blockquote>#', $content, $matches );

Escape sequences:

\s - any whitespace character
\S - any character that is not a whitespace character

Try this code and if there is any class with blockquote then add in this code:

preg_match_all( '/<blockquote>(.*?)<\/blockquote>/', $content, $matches );

本文标签: How to display quote format by pregmatch function