Is there any faster way instead of using preg_match in the following code? this code finds if there is the string 2004 in &lt;date_iso&gt;&lt;/date_iso&gt; and if it is so, I echo some data from that specific element that the search string was found.

I was wondering if this is the best/fastest approach because my main concern is speed and the XML file is huge. Thank you for your ideas.

this is a sample of the XML

&lt;entry ID="4406"&gt;
    &lt;id&gt;4406&lt;/id&gt;
    &lt;title&gt;Book Look Back at 2002&lt;/title&gt;
    &lt;link&gt;http://www.sebastian-bergmann.de/blog/archives/33_Book_Look_Back_at_2002.html&lt;/link&gt;
    &lt;description&gt;&lt;/description&gt;
    &lt;content_encoded&gt;&lt;/content_encoded&gt;
    &lt;dc_date&gt;20.1.2003, 07:11&lt;/dc_date&gt;
    &lt;date_iso&gt;2003-01-20T07:11&lt;/date_iso&gt;
    &lt;blog_link/&gt;
    &lt;blog_title/&gt;
&lt;/entry&gt;


this is the code

&lt;?php
$books  = simplexml_load_file('planet.xml');
$search = '2004';
foreach ($books-&gt;entry as $entry) {
    if (preg_match('/' . preg_quote($search) . '/i', $entry-&gt;date_iso)) {
        echo $entry-&gt;dc_date;
    }
}
?&gt;
First of all, put up a timer so you know if things get better.

You're repeating '/' . preg_quote($search) . '/i'for each book. You should create the search string only once or else you are wasting time:

&lt;?php
$books  = simplexml_load_file('planet.xml');
$search = '2004';
$regex = '/' . preg_quote($search) . '/i';
foreach ($books-&gt;entry as $entry) {
    if (preg_match($regex, $entry-&gt;date_iso)) {
        echo $entry-&gt;dc_date;
    }
}
?&gt;


If you are only looking for 2004 or similar you might analyze if simpler functions would be faster e.g. strpos. 

Also the /i modifier might be unnecessary.