ths1104 geeké

Créer un fichier .txt en PHP

Posted in PHP by ths1104 on April 30, 2011

Ecrire à la fin d’un fichier .txt en PHP

Posted in PHP by ths1104 on April 29, 2011

Ecrire au début d’un fichier .txt en PHP

Posted in PHP by ths1104 on January 29, 2010

Extraire le code HTML d’une page web en PHP

Posted in PHP by ths1104 on January 29, 2010

Language : PHP
Input : url de la page.
Output : code html de la page.

function get_html($url) {
if (strtoupper(substr($url,0,7))==”HTTP://”) $url=substr($url,7);
$p = strpos($url,”/”);
if ($p===FALSE) {
$nom_domaine=$url;
$get=”/”;
}else {
$nom_domaine=substr($url,0,$p);
$get=substr($url,$p);
}
$errno=””; $errstr=””; $r=””;
$fp = fsockopen($nom_domaine, 80, $errno, $errstr, 15);
if($fp) {
socket_set_timeout($fp, 15);
fputs($fp,”GET $get HTTP/1.1\r\n”);
fputs($fp,”Host: $nom_domaine\r\n”);
$navigateur=$_SERVER[‘HTTP_USER_AGENT’];
fputs($fp,”User-Agent: $navigateur\r\n”);
fputs($fp,”Connection: Close\r\n\r\n”);
$r=””;
while(!feof($fp)) {
$r.=fgets($fp,1024);
}
fclose($fp);
// echo $r ;
return($r);
}
return(”);
}