Jump to content

problem with fopen()


jorre13

Recommended Posts

these are the warnings i get

 
Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Site\HSC\frameset\admin\populate.php on line 46 

Warning: fopen(http://www.haco.com/index.php) [function.fopen]: failed to open stream: No error in C:\Site\HSC\frameset\admin\populate.php on line 46 


Warning: fgets(): supplied argument is not a valid stream resource in C:\Site\HSC\frameset\admin\populate.php on line 50 

Warning: fclose(): supplied argument is not a valid stream resource in C:\Site\HSC\frameset\admin\populate.php on line 85 

 

this is my code:

 
<?php 
/* 
* populate.php 
* 
* Script for populating the search-database with words, 
* pages and word-occurences. 
*/ 
/* Connect to the database: */ 
ini_set('display_errors', 1); // 0 = uit, 1 = aan 
error_reporting(E_ALL); 

/*mysql_pconnect("localhost","root","Tamara:19;75") 
    or die("ERROR: Could not connect to database!"); 
mysql_select_db("HSC");*/ 

include '../../includes/connect.php'; 
/* Define the URL that sould be processed: */ 
$url = $_GET['url']; 
echo $url; 
echo "<br>"; 
if( !$url ) 
{ 
    die( "You need to define a URL to process." ); 
} 
else if( substr($url,0,7) != "http://" ) 
{ 
    $url = "http://$url"; 
} 
/* Does this URL already have a record in the page-table? */ 
$result = mysql_query("SELECT page_id FROM page WHERE page_url = \"$url\""); 
$row = mysql_fetch_array($result); 
if( $row['page_id'] ) 
{ 
    /* If yes, use the old page_id: */ 
    $page_id = $row['page_id']; 
    
} 
else 
{ 
    /* If not, create one: */ 
    mysql_query("INSERT INTO page (page_url) VALUES (\"$url\")"); 
    $page_id = mysql_insert_id(); 
    
} 
/* Start parsing through the text, and build an index in the database: */ 
$fd = fopen($url,"r"); 

while( $buf = fgets($fd,1024) ) 
{ 
    /* Remove whitespace from beginning and end of string: */ 
    $buf = trim($buf); 
    /* Try to remove all HTML-tags: */ 
    $buf = strip_tags($buf); 
    $buf = ereg_replace('/&\w;/', '', $buf); 
    /* Extract all words matching the regexp from the current line: */ 
    preg_match_all("/(\b[\w+]+\b)/",$buf,$words); 
    /* Loop through all words/occurrences and insert them into the database: */ 
    for( $i = 0; $words[$i]; $i++ ) 
    { 
        for( $j = 0; $words[$i][$j]; $j++ ) 
        { 
            /* Does the current word already have a record in the word-table? */ 
            $cur_word = strtolower($words[$i][$j]); 
            $result = mysql_query("SELECT word_id FROM word WHERE word_word = '$cur_word'"); 
            $row = mysql_fetch_array($result); 
            if( $row['word_id'] ) 
            { 
                /* If yes, use the old word_id: */ 
                $word_id = $row['word_id']; 
            } 
            else 
            { 
                /* If not, create one: */ 
                mysql_query("INSERT INTO word (word_word) VALUES (\"$cur_word\")"); 
                $word_id = mysql_insert_id(); 
            } 
             /* And finally, register the occurrence of the word: */ 
            mysql_query("INSERT INTO occurrence (word_id,page_id) VALUES ($word_id,$page_id)"); 
            print "Indexing: $cur_word<br>"; 
        } 
    } 
} 
fclose($fd); 
?> 


Link to comment
https://forums.phpfreaks.com/topic/44458-problem-with-fopen/
Share on other sites

the url i would try is local.  This page is part of a search engine. It will be the spider.

 

Sorry u missed the point...

 

local to the computer i.e. a file located on the server such as a text file.

 

according to the script your calling a URL it dosent matter it its localhost.

Link to comment
https://forums.phpfreaks.com/topic/44458-problem-with-fopen/#findComment-215910
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.