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 badges2 Answers
Reset to default 0Meta-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
版权声明:本文标题:How to display quote format by preg_match function? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745477324a2660019.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论