Forum Moderators: coopster

Message Too Old, No Replies

Regex problem when Similar Elements on Page

         

ukgimp

9:21 am on Sep 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a situation where most of the time a little bit of regex works fine but occasionally there is a secondary similar element on the page which can foul it up. I think I am nearly there but could use a little advice.

<form method="post" action="http://www.someurl.com"
name="somename">

with my regex

preg_match('/action\s*=\s*"([^"]+)"/i', $result, $actionval);

Now that takes it up to the URL, but if there is a second form on that page above it it does not work.

Is there an easy way to include the

name="somename"

into the regex.

Is this a monster task to complete.

Cheers

coopster

8:32 pm on Sep 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




Now that takes it up to the URL, but if there is a second form on that page above it it does not work.

preg_match() will stop searching after the first match. May be a job for preg_match_all() [php.net] if you need to match more than one.

Second part, if you want to include the value of the name attribute, and it always follows the action attribute, just add it to your existing regex

'/action\s*=\s*"([^"]+)".*name\s*=\s*"([^"]+)"/is'
Note the "s" modifier [php.net] here as well!