Jump to content

What does PREG_PATTERN_ORDER do?


doni49

Recommended Posts

PREG_PATTERN_ORDER do?  I tried it both on there and NOT on there.  In both cases the results looked the same to me.

I'm using the following to retrieve the name and default value of all the fields on the page (setting up a screen scraper).

[code]
preg_match_all('/<INPUT.*?NAME=(.*)[\s]+.*VALUE="(.*)">/imU',$page,$matches, PREG_PATTERN_ORDER);
[/code]

The following is the array that get's created by that code:
[quote](
    [0] => Array
        (
            [0] => <input name="action" type="hidden" value="transmit">
            [1] => <INPUT NAME=Fld1 TYPE=Text SIZE=2 MAXLENGTH=2  VALUE="">
            [2] => <INPUT NAME=Fld2 TYPE=Text SIZE=1 MAXLENGTH=1  VALUE="">
            [3] => <input type="submit" style="width:75px" name="transmit" value="Transmit">
            [4] => <input type="submit" style="width:75px" name="quit" value="Quit">
            [5] => <input type="submit" style="width:75px" name="exit" value="Exit">

        )

    [1] => Array
        (
            [0] => "action"
            [1] => Fld1
            [2] => Fld2
            [3] => "transmit"
            [4] => "quit"
            [5] => "exit"
        )

    [2] => Array
        (
            [0] => transmit
            [1] =>
            [2] =>
            [3] => Transmit
            [4] => Quit
            [5] => Exit
        )

)[/quote]

It would be SO much simpler for me if $match[0] contained all the matches from the first field and $match[1] had all the matches from the second field etc.  This is what I was HOPING "order" would do.

Is there someway to have it return the following instead of what it is giving me?
[quote]Array
(
    [0] => Array
        (
            [0] => <input name="action" type="hidden" value="transmit">
            [1] => <INPUT NAME=Fld1 TYPE=Text SIZE=2 MAXLENGTH=2  VALUE="">
            [2] => <INPUT NAME=Fld2 TYPE=Text SIZE=1 MAXLENGTH=1  VALUE="">
            [3] => <input type="submit" style="width:75px" name="transmit" value="Transmit">
            [4] => <input type="submit" style="width:75px" name="quit" value="Quit">
            [5] => <input type="submit" style="width:75px" name="exit" value="Exit">

        )

    [1] => Array
        (
            [0] => "action"
    [1] => transmit
           
        )
    [2] => Array
            [0] => Fld1
            [1] => ""

        }
    [3] => Array
            [0] => Fld2
            [1] => ""

        }
    [4] => Array
            [0] => "transmit"
            [1] => "Transmit"

        }
    [5] => Array
            [0] => quit
            [1] => "Quit"

        }
    [6] => Array
            [0] => exit
            [1] => "Exit"

        }

)[/quote]

Thanks!
Link to comment
Share on other sites

  • 3 weeks later...
http://us3.php.net/manual/en/function.preg-match-all.php

Really your only two options are:
[code]Array (
  Array ( Whole Matches ),
  Array ( First Matches ),
  Array ( Second Matches ),
  ...
)[/code]
or
[code]Array (
  Array ( Whole First Match, First Match First Capture, First Match Second Capture, ...),
  Array ( Whole Second Match, Second Match First Capture, Second Match Second Capture, ...),
  ...
)[/code]
I've generally found the latter (without the PREG_PATTERN_ORDER flag set) easier to work with.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.