I want to know a good preg_match pattern in php for extracting data between tags.
For example :
<page>
<username>someone</username>
<id>3020778</id>
<text xml:space="preserve"> The quick brown fox. </text>
</page>
This will give me the string "The quick brown fox".
I have tried using
preg_match('/<text(.*)?>(.*)?<\/text>/', $content, $match);
But it seems doesn't work on some other cases.
Does anyone have a better solution or pattern?
And does using simpleXML make it more faster than preg_match?
$page = simplexml_load_string($xml); echo $page->username, $page->id, $page->text;Also see A simple program to CRUD Node values of an XML file, Best XML Parser for PHP and Best Methods to parse HTML