I have been trying to get quotes from post content I have failed to find a perfect regular expression for it. How can I filter them out?

For Example if get_post_content() returns this below

<blockquote class="wp-block-quote is-style-large"><p>Every body makes me a better person</p><cite>Isakiye Afasha</cite></blockquote>
<p>This is a test quote post. I want to do better.</p>

I want to be able to create a function takes in the get_post_content() and returns an array() which may looks like

  ["p"=>"very body makes me a better person","cite"=>"Isakiye Afasha"],
  • 1
    You shouldn't be using regular expressions to parse HTML, it can only handle a small subset of edge cases. Instead you need to use an XML parser. If you're using the block editor you can use that and inspect block attributes to get the citation values instead – Tom J Nowell Oct 13 '20 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.