How to display quote format by preg_match function?

I have defined quote post format for the theme: Add post-formats for themeadd_theme_support( 'post-formats'

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 );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745477325a4629403.html

相关推荐

  • How to display quote format by preg_match function?

    I have defined quote post format for the theme: Add post-formats for themeadd_theme_support( 'post-formats'

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信