im trying to get the source code of a website,
i mange to do this with curl
snipt:
Expand|Select|Wrap|Line Numbers
- <?php
- $ch = curl_init("http://somesite.com/with/page/url.html");
- $fp = fopen("/tmp/site.txt", "w+");
- curl_setopt($ch, CURLOPT_FILE, $fp);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_exec($ch);
- curl_close($ch);
- fclose($fp);
- $hand = fopen("/tmp/site.txt","r");
- $lines ="";
- while(!feof($hand)){
- $lines .= fgets($hand);
- }
- $code = trim(substr($lines,strpos($lines,"<a"),strpos($lines,"</a>")));// i want <a></a> tag
- $herf =substr($code,10,100);// the numbers are bogus
- //at the end i am returring the tag or inserting it to a db
- fclose($hand);
- ?>
i want to know is there a better way... i dont want my server to open and close file every time one of the guys will run the script
is there a way to do it in the server memory to get a response faster?
thanks head