hello all
im trying to get the source code of a website,
i mange to do this with curl
snipt:
[CODE=php]<?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($ha nd)){
$lines .= fgets($hand);
}
$code = trim(substr($li nes,strpos($lin es,"<a"),strpos ($lines,"</a>")));// i want <a></a> tag
$herf =substr($code,1 0,100);// the numbers are bogus
//at the end i am returring the tag or inserting it to a db
fclose($hand);
?>
[/CODE]
this code is working fine but BUT
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
im trying to get the source code of a website,
i mange to do this with curl
snipt:
[CODE=php]<?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($ha nd)){
$lines .= fgets($hand);
}
$code = trim(substr($li nes,strpos($lin es,"<a"),strpos ($lines,"</a>")));// i want <a></a> tag
$herf =substr($code,1 0,100);// the numbers are bogus
//at the end i am returring the tag or inserting it to a db
fclose($hand);
?>
[/CODE]
this code is working fine but BUT
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
Comment