1

I am using curl to display a page response on a thank you page. The code looks something like this:

$curl_handle=curl_init(); curl_setopt($curl_handle,CURLOPT_URL,'http://www.site.com'); curl_exec($curl_handle); curl_close($curl_handle);

The page above 'www.site.com' has a hidden input value in it that looks something like this:

<input type="hidden" id="my_id" value="123" />

All i need to do is grab the value ('123') from this hidden input and echo it out on my page.

Would be grateful if anyone could help me out with this.

Thanks!

rob melino
  • 781
  • 2
  • 10
  • 18
  • possible duplicate of [Best methods to parse HTML with PHP](http://stackoverflow.com/questions/3577641/best-methods-to-parse-html-with-php) – Gordon Sep 02 '11 at 17:39

1 Answers1

2

You may use DOMDocument to parse HTML and get the value from the input element. I've not test this code, but quick code should look something like this:

$doc = new DOMDocument();
$doc->loadHTMLFile('http://www.site.com');
$id = $doc->getElementById('my_id')->getAttribute('value');

For example, cnn.com has the following html code on the front page.

<a id="nav-us" href="/US/" title="U.S. News Headlines Stories and Video from CNN.com">U.S.</a>

The following code would echo "U.S. News Headlines Stories and Video from CNN.com"

$doc = new DOMDocument();
$doc->loadHTMLFile('http://www.cnn.com');
$title = $doc->getElementById('nav-us')->getAttribute('title');
echo $title;
ntangjee
  • 301
  • 1
  • 2
  • hmm, sorry that is not working. i am adding echo $id; after your code and am not getting anything to echo out – rob melino Sep 02 '11 at 18:07
  • did you get any error message? I've just noticed that the function getElementsById should be getElementById (without s). my bad copy, paste, and modify :( – ntangjee Sep 02 '11 at 23:44