Jump to content

reading from source code using cURL?


avelonz

Recommended Posts

hey guys . I've only been doing PHP for a month or so.. so don't go hard on me :]

 

I need to make a function, that goes to a specific website, then read the websites source code. In the source code I want it to find this line:

 

<input type="hidden" value="904af2bb79a87e81275e246c1189f887" name="abaafaasdfsasdauddgy" >

 

on line 277. Then it gets the information in "value" , and define it as $key1.

Same with "name", I just want that one as $key2.

 

Can anyone point me in the right direction? :)

Link to comment
https://forums.phpfreaks.com/topic/138375-reading-from-source-code-using-curl/
Share on other sites

Without seeing the code may not work.. but it should..

 

<?php
$HTML = file_get_contents("http://thesite.com"); // OR $file[276]; from premiso code
if (preg_match('/<input type="hidden" value="([^"]*)" name="([^"]*)" >/sim', $HTML, $regs))
{
$key1= $regs[1];
$key2= $regs[2];
}

echo "Key1=$key1<br>Key2=$key2";
?>

If you want to use cURL, you can store the source (in $contents) with the following code:

 

<?php
$url = 'page url';
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_URL, $url);
$contents = curl_exec($c);
curl_close($c);
?>

  Quote

Without seeing the code may not work.. but it should..

 

<?php
$HTML = file_get_contents("http://thesite.com"); // OR $file[276]; from premiso code
if (preg_match('/<input type="hidden" value="([^"]*)" name="([^"]*)" >/sim', $HTML, $regs))
{
$key1= $regs[1];
$key2= $regs[2];
}

echo "Key1=$key1<br>Key2=$key2";
?>

 

thanks a lot, worked for me!  ;D

 

thanks to the other contributors too :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.