PHP – regex get anything between tag html/xml

i have string in xml tag like this, and i need get what is between <w:t> tag and between <w:r>


<?php
$xml =<<<XML
<w:p w:rsidR="00E" w:rsidRDefault="00E">
 <w:r>
  <w:t>$</w:t>
 </w:r>
 <w:r w:rsidR="000">
  <w:t>ary.two</w:t>
 </w:r>
 <w:r>
  <w:t>$</w:t>
 </w:r>
</w:p>
XML;

//  get all between w:t
preg_match_all('~<w:t>(.+?)<\/w:t>~', $xml, $m_t);

var_dump($m_t);

// get all between w:r
preg_match_all('~<w:r(.+?)<\/w:r>~s', $xml, $m_r);

var_dump($m_r);

?>

to get w:r why we need extra s ???

becouse the $xml have newlines

(readmore)

Published by

G3n1k

just to remember what i had known :)

One thought on “PHP – regex get anything between tag html/xml”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s