J'ai un scipt PHP qui permet de faire une recherche sur mon site web. Le résultat de la recherche est un "include" situé au milieu d'une page comportant du code HTML.
La page est codée comme ceci :
Code : Tout sélectionner
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
Voilà un exemple : http://www.molos.ch/search2.php?q=presa
Et le script PHP :
Code : Tout sélectionner
<?php
error_reporting(E_ALL & ~E_NOTICE);
// Free script to search your site
// Copyright 2004, Digital Point Solutions
// version 1.2 - August 2, 2004
//
// Feel free to format the results however you see fit, the only thing we ask is that you leave a link to us in case others would like to add it to their site.
// Links will be checked, and removal of the link could result it your website being blocked from using the service.
// Other than that, have fun! :) - Shawn
// Set your parameters here
$key = "q7xLCulQFHLTMPK0/nV/I1qrk4v/X/yo"; // This is your Google API key, if you don't have one, get one for free at:
// https://www.google.com/accounts/NewAccount?continue=http://api.google.com/createkey&followup=http://api.google.com/createkey
$site = "www.molos.ch"; // This is the site you wish to search within
// If Google has you indexed without "www.", don't specify "www." within your site URL.
// 'http://' is *not* required in the site variable.
// Examples:
// www.cnn.com search within www.cnn.com
// www.cnn.com/tech/ search within www.cnn.com/tech/
//
// You can also leave it blank to search the entire web
$spelling = 0; // Change this to 0 if you do not want to check for spelling suggestions
// Using this option makes searches twice as long, because it requires 2 queries instead of 1
// Colors
$color_border = "#ffffff";
$color_title = "#ffffff";
$color_odd_results = "#ffffff";
$color_even_results = "#ffffff";
$q = stripslashes ($HTTP_GET_VARS['q']);
$start = 0 + $HTTP_GET_VARS['start'];
ini_set ("allow_url_fopen", "1");
if (!ini_get ("allow_url_fopen")) echo '<FONT COLOR=RED><B>Sorry, this PHP configuration does not allow for usage of <A HREF="http://www.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen" TARGET="_blank">fopen()</A>, which is required for this search engine script.</B></FONT><P>';
// Let's get the results
$handle = @fopen ("http://search.digitalpoint.com/?q=" . urlencode ($q) . "&key=" . urlencode ($key) . "&site=" . urlencode ($site) . "&start=" . min (990, $start) . "&spell=" . $spelling, "r");
while (!feof ($handle) && $handle) {
$line .= fgets ($handle, 1024);
}
fclose($handle);
eval ('$urls = ' . $line . ';');
echo '<TABLE class="align-justify" BGCOLOR=' . $color_border . ' CELLSPACING=1 CELLPADDING=0><TR><TD><TABLE class="align-justify" BGCOLOR=' . $color_odd_results . ' border=0 CELLSPACING=0 CELLPADDING=6><TR BGCOLOR=' . $color_title . '><TH COLSPAN=3>';
echo '<TABLE class="align-justify" border=0 WIDTH=100%><TR><TH class="align-justify" WIDTH=80 ALIGN=CENTER VALIGN=MIDDLE><FONT SIZE=-1><A HREF="http://www.digitalpoint.com/tools/search/">Add Search<BR>To Your Site</A></FONT></TH><TH ALIGN=CENTER>';
echo ' ';
if ($urls['end'] - $urls['start'] < 9) $urls['results'] = $urls['end'];
if ($urls['results'] > 10) {
if ($start < 40) {
$x = 0;
} else {
$x = round (max (0, min ($start - 40, $urls['results'] - 96) / 10));
}
for ($i = $x; $i < $x + 10; $i++) {
if ($i != round ($start / 10)) {
echo '<A HREF="search.php?q=' . urlencode($q) . '&start=' . ($i * 10) . '">' . ($i + 1) . "</A> ";
} else {
echo ($i + 1) . " ";
}
if (max (10, ($i + 1) * 10) >= $urls['results']) break;
}
echo '<BR>';
}
echo '<FONT SIZE=+1>Estimated Total Results: ' . number_format ($urls['results']) . '</FONT>';
if ($urls['spelling']) echo '<br><font color="red">Did you mean: <a href="search.php?q=' . urlencode($urls['spelling']) . '">' . $urls['spelling'] . '</a></font>';
echo '</TH><TH WIDTH=80> </TH></TR></TABLE>';
$rownum = 1;
$start = $urls['start'];
if ($urls['error']) {
echo "<TR COLSPAN=3><TD><BR><FONT SIZE=-1 COLOR=RED>" . $urls['error'] . "</FONT></TD></TR>";
} else {
foreach ($urls['urls'] as $key => $url) {
$rownum++;
echo "<TR";
if ($rownum % 2 == 1) echo ' BGCOLOR=' . $color_even_results;
echo "><TH ALIGN=RIGHT WIDTH=35>#" . ($key + $start) . ": </TH><TD class='align-justify'><A HREF=\"$url\" class=align-justify>" . $urls['titles'][$key] . "</A><BR>" . $urls['snippet'][$key] . "<BR><span class=align-justify> <B>$url</B></span></TD><TD> </TD></TR>";
}
}
echo '</TABLE></TD></TR></TABLE>';
?>
