2016-07-04 4 views
0

私はMySQLテーブルのリンクでいっぱいのデータベースを持っており、それぞれを解析して出力を新しいファイルに移動したいと思います。残念ながら、whileループの中でインクルード( "getContent.php")を使用するたびに「can not redeclare file_get_html()」というエラーが出ます。1つのスクリプトで一連のWebページでfile_get_htmlを使用する方法はありますか?

私の主なスクリプトが

<?php 
$db = 'newsfeed'; 
$zeta = 0; 
$beta = 0; 
// connect to RDS instance MySQL Database Newsfeed 
include_once('/var/www/dbfunctions/mysqli_connectdb.php'); 

// set content source table 
$sourcetable = 'feedsources'; 
$mastertable = 'mastertable'; 

// set date to remove results older than 
date_default_timezone_set("UTC"); 
$datenow = date_timestamp_get(date_create()); 
$offset = "86400"; 
$deldate = $datenow - $offset; 

//begin cycling through content data 

//delete all "old" entries from the mastertable 

//get number of source items present 
$itemquery = "SELECT id,name FROM $sourcetable"; 
$itemresult = mysqli_query($conn, $itemquery); 

while ($row = mysqli_fetch_assoc($itemresult)) { 
$sourceid = $row['id']; 
$sourcename = $row['name']; 

     // cycle throught the data tables 
     $dataquery = "SELECT * FROM $sourcetable WHERE id = $sourceid;"; 

     $dataresult = mysqli_query($conn, $dataquery); 

     while ($row = mysqli_fetch_assoc($dataresult)) { 
     $table = $row['datatable']; 
     } 

     // copy all data from the targetted table into the master table 


     //loop through the targetted table and copy to mysql 
     $getdata = "SELECT * FROM ".$table.";"; 
     $datareturn = mysqli_query($conn, $getdata); 

     while ($row = mysqli_fetch_assoc($datareturn)) { 
       $date = $row['datecreated']; 
       $title = addslashes($row['title']); 
       $url = addslashes($row['url']); 
       $tags = addslashes($row['tags']); 
       $titleid = $row['id']; 

     //get content and place in html file in /var/www/html/nuzr/content/ 

       include("getcontent.php"); 
       echo $filename; 
       //check whether the item already exists in the table 
       $checkquery = "select id from ".$mastertable." where title = '".$title."';"; 

       $checkcheck = mysqli_query($conn, $checkquery); 

       if(mysqli_num_rows($checkcheck) > 0){ 
       echo "CHECKFAILED"; 
       }else{ 

       $copy = "INSERT INTO ".$mastertable." VALUES ('NULL','$table','$sourcename','$date','$title','$url','$tags','$filename');"; 
       mysqli_query($conn, $copy); 

       echo "Beta is ".$beta; 
       $beta = $beta + 1; 
         } 
       } 
     // clean the master table 
     $delquery = 'DELETE FROM '.$mastertable.' WHERE datecreated < '.$deldate.';'; 

     mysqli_query($conn, $delquery); 

} 

function clear() 
{ 
    $this->dom = null; 
    $this->parent = null; 
    $this->parent = null; 
    $this->children = null; 
} 

?> 

あるとgetcontent.phpスクリプトはやや厄介なプログラムのための

<?php 
//Check Start 
//echo "Program Starts"; 

// Include the library 
include('/var/www/tools/dom/simple_html_dom.php'); 

$source = $url; 
$content = array(); 
$header1 = array(); 
$header2 = array(); 
$i = 0; $y = 0; 

// Retrieve the DOM from a given URL 
$html = file_get_html($source); 

     //grab headers in case initial title is a header 
     foreach($html->find('h1') as $e){ 

       $header1[$i] = $e->outertext; 

       //echo $e->outertext; 

       $i = $i + 1; 
     } 

     $i = 0; 

     foreach($html->find('h2') as $e){ 

       $header2[$i] = $e->outertext; 

       //echo $e->outertext; 

       $i = $i + 1; 
     } 

     //reset counter 
     $i = 0; 

     // Find all paragraph tags and print their content into a text file 
     foreach($html->find('p') as $e){ 

       $content[$i] = $e->outertext; 

       //echo $e->outertext; 

       $i = $i + 1; 
     } 

//create the content storage file 
$filename = "/var/www/html/nuzr/content/".$table.$titleid.".html"; 
echo "The filename is".$filename; 
$file = fopen($filename,"a"); 

// write header and link to original article 
$titleblurb = "<b>Original article courtesy of <a href='".$url."'>".$sourcename."</a></b>"; 
fwrite($file, $titleblurb); 

// set site specific parameters based on header/footer size 
if($sourcename == "The Globe and Mail"){ 

//Set indexing parameters 
$z = $i - 13; $y = 2; 

     //Add Header content 
     $text = $header1[0]; 
     fwrite($file, $text); 
     $text = $header2[1]; 
     fwrite($file, $text); 

}elseif($sourcename == "CNN Money"){ 

//Set indexing parameters 
$z = $i - 3; $y = 1; 

     //Add header content 
     $text = $header1[0]; 
     fwrite($file, $text); 
     $text = $header2[1]; 
     fwrite($file, $text); 

}elseif($sourcename == "CNN Markets"){ 

//Set indexing parameters 
$z = $i - 3; $y = 1; 

     //Add header content 
     $text = $header1[0]; 
     fwrite($file, $text); 
     //$text = $header2[1]; 
     //fwrite($file, $text); 

}elseif($sourcename == "BBC Business"){ 

//Set indexing parameters 
$z = $i - 9; $y = 1; 

     //Add header content 
     $text = $header1[0]; 
     fwrite($file, $text); 
     //$text = $header2[1]; 
     //fwrite($file, $text); 

}elseif($sourcename == "BBC Politics"){ 

//Set indexing parameters 
$z = $i - 0; $y = 1; 

     //Add header content 
     $text = $header1[0]; 
     fwrite($file, $text); 
     //$text = $header2[1]; 
     //fwrite($file, $text); 

}else{ 
echo $sourcename; 
} 

     do{ 

     $text = $content[$y]; 
     fwrite($file, $text); 
     $y = $y +1; 

     }while($y<$z); 

echo "Zeta is".$zeta; 
$zeta = $zeta +1; 

//close the content file 
fclose($file); 

//echo "File end."; 

$html->clear(); 
unset($html); 





?> 

謝罪です。私は、問題のトラブルシューティングの過程で多くのカウンタやものを追加しました。

ご意見をいただければ幸いです。現在、プログラムは致命的なエラーを経験し、実行されません。私は人々に同様の問題があったいくつかの状況を見てきました。include()の代わりにinclude_once()を使用することが推奨されていましたが、これは目的のURLの1つだけを解析するので機能しません。

答えて

0

あなたは別のファイルにこの関数を作る、または

if (!method_exists('file_get_html')) { 
    function file_get_html() {} 
} 
+0

申し訳ありませんに貼り付けたが...それだけで二回目を実行しているからそれを停止し、これだけの1を生じないことができますいずれか私のURLの処理は? – AttemptedDevelopment

+0

tryを置き換えてください( '/ var/www/tools/dom/simple_html_dom.php'); require_once( '/ var/www/tools/dom/simple_html_dom.php'); – Dry7

+0

ああ。私は文字通り、これがこれまでにない愚かな間違いであることを実感しました。私はgetcontentプログラムをループしていますが、ライブラリ宣言を含んでいます。私はちょうど( '/ var/www/tools/dom/simple_html_dom.php')行をインクルードしました。私の主要なルーチンに入り、それはすべて機能します。ご協力いただきありがとうございます。私はプライマリ・ルーチンにも集中していた。 – AttemptedDevelopment

関連する問題