0

I need to capture only the values of html inputs returned from curl_exec () function. This function returns the full html of the page, is there any way to take only the values of the inputs?

my code:

public function searchUser(Request $request){

    $data = $request->all();

      $cURL = curl_init('http://www.example.com/result.php');

      curl_setopt($cURL, CURLOPT_HEADER, false);
      curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);

      $dados = array(
        'num_cnpj' => $data['cnpj'],
        'botao' => 'Consultar'

      );
      curl_setopt($cURL, CURLOPT_POST, true);
      curl_setopt($cURL, CURLOPT_POSTFIELDS, $dados);

      curl_setopt($cURL, CURLOPT_REFERER, 'http://www.example.com/index.php');

      $result = curl_exec($cURL);

      curl_close($cURL);

    return $result;

}
1
  • There is no function which can help you with like this. You'll either need to write a parser which can get you those values or you can implement a rest api to get data. Commented Feb 12, 2016 at 13:28

1 Answer 1

0

You could try using one of the many PHP dom parsers.

http://php.net/manual/en/domdocument.loadhtml.php

<?php
# Create a DOM parser object
$dom = new DOMDocument();

# Parse the HTML
# The @ before the method call suppresses any warnings that
# loadHTML might throw because of invalid HTML in the page.
@$dom->loadHTML($result);

# Iterate over all the <input> tags
foreach($dom->getElementsByTagName('input') as $input) {
        # Show the attribute value
        echo $input->getAttribute('value');
        echo "<br />";
}
?>
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for answer, but the method$dom->getElementsByTagName('input') is not capturing inputs, returning empty.
Oh sorry, my html was not returning inputs but a table with the results, changing the input tag for td and is now working. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.