Jump to content

Getting "Input" Values


doni49

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";

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.