avelonz Posted December 25, 2008 Share Posted December 25, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/138375-reading-from-source-code-using-curl/ Share on other sites More sharing options...
Sakesaru Posted December 25, 2008 Share Posted December 25, 2008 Their source code, or the HTML of a file? Quote Link to comment https://forums.phpfreaks.com/topic/138375-reading-from-source-code-using-curl/#findComment-723569 Share on other sites More sharing options...
avelonz Posted December 27, 2008 Author Share Posted December 27, 2008 Their source code, or the HTML of a file? the viewable source code on the site.. (like the "View Source Code" in Firefox) Quote Link to comment https://forums.phpfreaks.com/topic/138375-reading-from-source-code-using-curl/#findComment-724528 Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 file Will put it into an array then just $file = file('http://thesite.com'); echo $file[276]; Should echo that line as long as it is always on line 277. Quote Link to comment https://forums.phpfreaks.com/topic/138375-reading-from-source-code-using-curl/#findComment-724542 Share on other sites More sharing options...
MadTechie Posted December 27, 2008 Share Posted December 27, 2008 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/138375-reading-from-source-code-using-curl/#findComment-724575 Share on other sites More sharing options...
thebadbad Posted December 27, 2008 Share Posted December 27, 2008 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 Link to comment https://forums.phpfreaks.com/topic/138375-reading-from-source-code-using-curl/#findComment-724581 Share on other sites More sharing options...
avelonz Posted December 29, 2008 Author Share Posted December 29, 2008 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! thanks to the other contributors too Quote Link to comment https://forums.phpfreaks.com/topic/138375-reading-from-source-code-using-curl/#findComment-725051 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.