doni49 Posted April 1, 2007 Share Posted April 1, 2007 I'm working on a screen scraping app (to perform tasks on my own WHM panel) and I'm having a bit of difficulty. I need to retrieve the "Value" of ever input put field. Here's a trimmed down copy of what I need to pull the data from. $response = ' <tr><br> <td class="densetbl-key">Max FTP Accounts</td><br> <td class="densetbl-value"><input value="10" type="text" name="maxftp"></input></td><br> </tr><br> <tr><br> <td class="densetbl-key">Max Email Accounts</td><br> <td class="densetbl-value"><input type="text" value="250" name="maxpop"></input></td><br> </tr><br>'; In this example, I need to retrieve 250 from the second input field. Heres what I've tried (and many variations of this) but $match keeps coming back as empty. preg_match('/(\w|\s*)<input value="(\w+)" type="text" name="maxpop">(\w|\s*)/mU',$response,$match); Thanks a bunch! Quote Link to comment Share on other sites More sharing options...
fert Posted April 2, 2007 Share Posted April 2, 2007 try this preg_match('/(.*)<input value="(.*)" type="text" name="maxpop">(.*)/mU',$response,$match); print_r($match); Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 2, 2007 Author Share Posted April 2, 2007 Thanks for the reply. That helped. But it didn't work for all the fields. So I investigated further. I noticed that the fields change the order for value, name and type for example: <input value="value" name="name" type="text"> <input name="name" value="value"type="text"> <input type="text" value="value" name="name"> This sounds like a case for back references. But this is one of the things about regex that I've had the most trouble with. Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 2, 2007 Author Share Posted April 2, 2007 I've got something that I think SHOULD work, but it's not. In theory, it should look at every input and allow name & value to be at any position inside the angle brackets. preg_match('/.*<input.+[[value="(.+)"|name="maxpop"]\s+]{1,2}.*>.*/imU',$response,$match); echo "<pre>"; print_r($match); echo "</pre>"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.