خوب بخيال شدم اينم كد يك فايل درست كن به نام search_engine.class.php
بعدش اين كد داخلش كپي كن :
<?php
class searchEngine{
function openFile($file){
if($fp = fopen($file,"r")){
$content = explode("\n",fread($fp, filesize($file)));
fclose($fp);
}else{
echo "FALHA AO ABRIR O FICHEIRO";
}
return $content;
}
function printOutput($lineName, $lineLink, $word){
echo "Resultados da pesquisa por <u>". $word ."</u><br /><hr /><br />";
for($i=0;$i<count($lineName);$i++){
echo "<a href=\"". $lineLink[$i] ."\" target=\"_blank\" title=\"". $lineName[$i] ."\">". $lineName[$i] ."</a><br />";
}
}
function searchLine($content, $word){
for($j=0; $j<count($content); $j++){
$line = explode(';', $content[$j]);
for($i=2; $i<count($line); $i++){
if($line[$i] == $word){
$lineName[] = $line[0];
$lineLink[] = $line[1];
}
}
}
if(empty($lineName)){
echo "A pesquisa por <u>". $word ."</u> nمo retornou resultados!";
}else{
$this->printOutput($lineName, $lineLink, $word);
}
}
}
?>
حالا يك فايل ديگه درست كن به نام main.php واينم كدش
<html>
<body>
<?php
require_once("search_engine.class.php");
$search = new searchEngine();
$content = $search->openFile("bdsearch.txt");
$search->searchLine($content, $_GET['w']);
if(isset($_GET['l'])){
for($p=0;$p<count($content);$p++){
$line=explode(';' ,$content[$p]);
for($k=0;$k<count($line);$k++){
echo $line[$k] .";";
}
echo "<br />";
unset($line);
}
}
?>
</body>
</html>
خوب اگه به مشكل خوردي همون كاري كه گفتم انجام بده فقط بايد يكم دستكاريش كني