PREG search for multiple values in one pass?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am trying to do a search through some data, more specifically HTML,
to extract data from it. So for example I may have:

<b>Title:</b> <em>This is a title</em>
<b>Name:</b> <em>Fred</em>

I wish to grab the data "This is a title" and "Fred" against their
corresponding headings in an array (e.g. $array[title] = "This is a
title") .... but the key doesn't matter, that need not come from the
regexp but I can do manually.

The question is - how do I do this in one pass? Do I just use use
nested OR's in my regexp? The problem with this though, is once a match
is made, how does PHP then tell me what it corresponds to if it's an
OR? (it just returns the match surely?)

Actually i'm not even too sure how to go about doing this... do I need
backreferencing etc...? I've read the pages but couldn't
entirely make sense of the various preg functions.

Thanks a bunch!


Re: PREG search for multiple values in one pass?

*** escribió/wrote (18 Aug 2006 18:46:28 -0700):
Quoted text here. Click to load it

I'm unsure about your exact needs, but I hope this code helps:

$text='<b>Title:</b> <em>This is a title</em>
<b>Name:</b> <em>Fred</em>';


This prints:

    [0] => Array
            [0] => <b>Title:</b> <em>This is a title</em>
            [1] => <b>Name:</b> <em>Fred</em>

    [1] => Array
            [0] => Title:
            [1] => Name:

    [2] => Array
            [0] => This is a title
            [1] => Fred


If keys don't matter, must ignore them: '@<b>.*</b>.*<em>(.*)</em>@Ui'

-+ - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web:
+- Mi web de humor con rayos UVA:

Site Timeline