Rodrigo de Oliveira Costa wrote:
Hi guys, I'm trying to retrieve a certain variable from a site. Here it
goes:
The site has a SELECT box that is dynamicaly updated, I need to put a
script running that will retrieve the specified SELECT with its
contents, that are labels and values. Is there a way to retrieve the
page and then select just one line of the code, discard the rest and
then retrieve from this line the values?
Here goes the SELECT :
<SELECT title='navigation' Name=navigating onChange="self.location =
'/s/2318355/'+ this.options[this.selectedIndex].value + '/';"><option
value=1 selected>1. Name<option value=2 >2. Name</select>
I need to get something like this:
$select = navigating;
$label1 = "1.Name";
$value1 = 1;
$label2 = "2.Name";
$value2 = 2;
Remmembering that the SELECT is dynamic so I need also to check how
many labels and values there are and store them into variables. I
getting a really hard time doing this.
I thank any imput you guys can give me.
Thanx,
Rodrigo
First, get the file using file_get_contents(). Now, do two nested
regular expression matches. As in, do a regular expression match to get
all the <select></select> blocks, and then for each match do another
regular expression match to grab all the <option> blocks.
Alternatively, you could do this with strpos(), since it lets you
specify where to START searching from. It might be faster, but it would
probably end up being less flexible.
Alternatively, if you need a super robust solution, you might want to
look into actual HTML parsing libraries, like tidy (which has a PHP module).
Regards, Adam Zey.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php