Hallo Julian
Fehlt da nicht ein [$i]?
wo fehlt denn da eins? str_replace($formatiert[$i],...
hatte ich bereits versucht hat auch nicht geklappt. Dann vertauscht er mir die Wörter.
Du solltest dir außerdem mal foreach() anschauen.
mit foreach() habe ich das gleiche ergebniss.
hier einmal der komplette code - ist vielleicht leichter:
<?php
if(!$c) {
?>
<form action='index.php?c=1' method=POST>
<b>Suche: </b>
<input type='text' length=40 name='any'>
<input type='submit' value='Suchen'>
</form>
<?
} else if($c) {
print "<form action='index.php?c=1' method=POST><font face='Arial'>
<b>Suche: </b>
<input type='text' length=40 name='any' value='" . $_REQUEST['any'] . "'>
<input type='submit' value='Suche'>
</form> ";
MySQL_connect("localhost", "root", "");
MySQL_select_db("test");
if((!$any) || ($any == "")) { $any = ""; } else { $any = "+(".$any.")"; }
$query = "
SELECT *,
MATCH(title, body) AGAINST ('$any' IN BOOLEAN MODE) AS score
FROM articles
WHERE MATCH(title, body) AGAINST ('$any' IN BOOLEAN MODE)";
$artm1 = MySQL_query($query);
$anzahl_daten = mysql_num_rows($artm1);
if(!$artm1) {
echo MySQL_error()."<br>$query<br>";
}
echo "<i>" . $anzahl_daten . " </i>Suchergebnisse für <i>" . $_REQUEST['any'] . "</i><br><br><hr>";
if(MySQL_num_rows($artm1) > 0) {
while($artm2 = MySQL_fetch_array($artm1)) {
//
// VARIABLEN
//
$val = round($artm2['score'], 3);
$val = $val*100;
$mystring = $artm2['body']; // wo wird gesucht?
$search = $_REQUEST['any']; // was wird gesucht?
$ab = 0; // von wo ab soll der string gesucht werden?
$pos = strpos($mystring, $search); // auf welcher position befindet sich mein string
if ($pos < 100) {
$start = 0;
}
else {
$start = $pos - 100;
}
$length = 200; // die länge der Zeichen nach dem gesuchten wort
$ergebnis = substr($mystring, $start, $length); // hier wird der text geschnitten
$string_ergebnis = str_replace($search, $ersetzung, $ergebnis); // formatierter text
//
//
//
echo "<a href='#'>" . $artm2['title'] . "</a><br>...";
$formatiert = explode("+", $_REQUEST['any']);
// Test mit for-schleife
/* for($i = 0; $i < count($formatiert); $i++){
$ok_format = " <b>" . $formatiert[$i] . "</b>";
echo str_replace($formatiert[$i], $ok_format, $ergebnis); // formatierter text
} */
// Test mit foreach
foreach($formatiert as $mach_format){
$ok_format = " <b>" . $mach_format . "</b>";
echo str_replace($mach_format, $ok_format, $ergebnis); // formatierter text
}
echo "...<font color='#B0B0B0'><br>http://www.seite.de/index.php?id=234 - 13.Juli 2004<br><br></font>";
}
}
else {
echo "Es wurden leider keine Ergebnisse gefunden, die Ihren Suchkriterien entsprechen.<br>";
}
echo "<br><br><br>";
}
?>
Wie gesagt, explode() funktioniert auch komischerweise nicht und mit str_replace kann leider nur dann den text formatieren wenn er 100% richtig geschrieben wurde.
Gruß Alex.