0

i have 2 sites: foo.com and bar.com

foo.com has form with content from its database. what i want is to get that content from each input, textarea in the form.

I can access to the code of the foo.com via curl (at bar.com):

    <?php
     $post='pswd';        
     $site='foo.com';
     $c = curl_init();
     curl_setopt($c, CURLOPT_URL, $site);
     curl_setopt($c, CURLOPT_POST, 1);
     curl_setopt($c, CURLOPT_POSTFIELDS, "pswd=$post");
     curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
     $page = curl_exec($c);
     curl_close($c);
     ?>

and i get whole html with form and inputs like:

    <textarea name="inputname" class="longone">inputcontent</textarea>

and i have no idea how to start extracting datas and save it in this way:

$inputname='inputcontent';

could you give me any advice? thank you in advance

EDIT:

I forgot to tell you that i know some of the inputnames and the others vary only the last chars - number e.g. inputnameiknow1, inputnameiknow2 ...

Edit 2 - solution thanks to baba

  1. simplehtml dom uses file_get_contents so to send vars as POST follow: How to post data in PHP using file_get_contents?

  2. to get input names just ask for 'name'

so my code looks like Baba's but added

$element->name

to extract inputname

Community
  • 1
  • 1
andrewpo
  • 361
  • 1
  • 6
  • 14

1 Answers1

1

Hello I think you should use Simple HTML DOM Parser since you are not vast with regular expressions

Example

$html = file_get_html('http://www.examle.com/');

// Find all images 
foreach($html->find('textarea') as $element) 
       echo $element->plaintext . '<br>';

Job Done

Baba
  • 94,024
  • 28
  • 166
  • 217