Sostituire file_get_contents ?

lorenzo.211

Utente Attivo
28 Set 2009
41
0
0
Ciao ragazzi!
Ho scoperto che la funzione file_get_contents non si puo usare per fare il mio script
http://forum.it.altervista.org/php-mysql-e-file-database/75445-errore-file_get_contents.html ( è il link della discussione che mi ha fatto scoprire questo)

Siccome, dopo varie googlate , non ho ancora capito a cosa serve , posso trovare un sostituto di questa funzione ?

Ecco il mio script
PHP:
<?php 
ini_set("memory_limit","64M");
$contatore = 0;


function ins(){
global $contatore;
echo $contatore;

if ($contatore == 0){
	$url = "http://localhost:8888/prova.html";
	$contatore++;

}elseif ($contatore >= 1){
	$ide=fopen("nome.txt","r");
	$ide=fread($ide,filesize("nome.txt"));
	echo $ide;
	$url = $ide;
	

}




$input = file_get_contents($url);
echo $input;

$regexp = '/<a([a-zA-Z0-9=" ]*)href="([A-Z:\/a-z0-9._-]*)"([a-zA-Z0-9=" ]*)>([a-zA-Z0-9., :;\/-_()<>!?]*)<\/a>/i';
preg_match_all($regexp, $input, $matches);
foreach($matches[2] as $match) 
{
    
$db_host = "localhost";
$db_user = "root";
$db_password = "root";
$db_name = "prova";


$db = mysql_connect($db_host, $db_user, $db_password);
  if ($db == FALSE)
    die ("Errore nella connessione. Verificare i parametri nel file config.inc.php");

  mysql_select_db($db_name, $db)
     or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
$nome=$match;

$identificatore = fopen("nome.txt", "w");

// Scrivo i dati nel file
fwrite($identificatore, $nome);

// Chiudo il file
fclose($identificatore);

$query="insert into utenti(nome) VALUES ('$nome')";
if (mysql_query($query, $db))
    echo "Inserimento corretto";
  else
    echo "Errore durante l'inserimento";
  

mysql_close($db); 
}


ins();

}



ins();




?>

Grazie!
 
ho trovat il codice per ottenere il sorgente html ( ecco a che serviva la funzione di prima -.-") con le librerie curl, così:
PHP:
$url = "http://www.google.it";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$sorgente = curl_exec($ch);
curl_close($ch);

$a = highlight_string($sorgente);
però la funzione "highlight_string($sorgente)" stampa sempre a video il codice sorgente e io non lo devo visualizzare ,come posso fare?
 
vuoi utilizzare highlight_string() ma non vuoi che produca l'output?
 
bene -.-"

PHP:
<?php 
ini_set("memory_limit","64M");
$contatore = 0;


function ins(){
global $contatore;


if ($contatore == 0){
	$url = "http://localhost:8888/prova.html";
	$contatore++;

}elseif ($contatore >= 1){
	$ide=fopen("nome.txt","r");
	$ide=fread($ide,filesize("nome.txt"));
	$url = $ide;
	

}





$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$sorgente = curl_exec($ch);
curl_close($ch);


$input=highlight_string($sorgente, true);



$regexp = '/<a([a-zA-Z0-9=" ]*)href="([A-Z:\/a-z0-9._-]*)"([a-zA-Z0-9=" ]*)>([a-zA-Z0-9., :;\/-_()<>!?]*)<\/a>/i';
preg_match_all($regexp, $input, $matches);
foreach($matches[2] as $match) 
{
    
$db_host = "localhost";
$db_user = "root";
$db_password = "root";
$db_name = "prova";


$db = mysql_connect($db_host, $db_user, $db_password);
  if ($db == FALSE)
    die ("Errore nella connessione. Verificare i parametri nel file config.inc.php");

  mysql_select_db($db_name, $db)
     or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
$nome=$match;

$identificatore = fopen("nome.txt", "w");

// Scrivo i dati nel file
fwrite($identificatore, $nome);

// Chiudo il file
fclose($identificatore);

$query=mysql_query("INSERT INTO utenti(nome) VALUES ('$nome')");
if (mysql_query($query, $db))
    echo "Inserimento corretto";
  else
    echo "Errore durante l'inserimento";
  

mysql_close($db); 
}


ins();

}



ins();




?>
Ecco il codice ho fatto come dite voi , però non inserisce niente nel database e non esce neanche "Errore durante l'inserimento" e come se si bloccasse dopo la funzione curl ....
 

Discussioni simili