Verfasst: 24.08.2005 21:59
Manche Probleme lösen sich von selbst. Ich hatte bis eben nicht mehr an den Code gedacht. Bei uns läuft mein zuletzt geschriebener Codefetzen ganz anständig.
Grüße,
Gérome
Grüße,
Gérome
phpBB.de - Die deutsche phpBB-Community
https://www.phpbb.de/community/
Code: Alles auswählen
$entry = preg_replace('/(?<= )([\S]{1,2}|[\S]{21,})(?= )/',' ', $entry);
das heisst doch, er indiziert alle zeichen von 2 bis 21 buchstaben länge?Scotty hat geschrieben:Ja den hab ich auch ausprobiert, war auch ein guter Ansatz, aber so ist es besser:
Gefunden auf: phpbb.com
So muss das sein, damit es Funktioniert:Code: Alles auswählen
$entry = preg_replace('/(?<= )([\S]{1,2}|[\S]{21,})(?= )/',' ', $entry);
Code: Alles auswählen
<?php
$entry = 'es ja er es du da 01 02 03 04 05 06 07 08 09 1 2 3 4 5 6 7 8 9
normale wörter mit sönderzäißchün desoxyribonukleinsäure desoxyribonukleinsäure
desoxyribonukleinsäure desoxyribonukleinsäure 1 1 1 1 desoxyribonukleinsäure
desoxyribonukleinsäure desoxyribonukleinsäuredesoxyribonukleinsäure';
$entry = ' ' . strip_tags(strtolower($entry)) . ' ';
// Original
$entry1 = preg_replace('/[ ]([\S]{1,2}|[\S]{21,})[ ]/',' ', $entry);
echo('1.: ' . $entry1 . '<br />');
// Code von Gérome phpBB.de
$entry2 = preg_replace('/(\b)([\S]{1,2}|[\S]{21,})(\b)/',' ', $entry);
echo('2.: ' . $entry2 . '<br />');
// Code von Lese phpBB.com
$entry3 = preg_replace('/(?<= )([\S]{1,2}|[\S]{21,})(?= )/',' ', $entry);
echo('3.: ' . $entry3 . '<br />');
?>
1.: ja es da 02 04 06 08 1 3 5 7 9 normale wörter mit sönderzäißchün desoxyribonukleinsäure desoxyribonukleinsäure 1 1 desoxyribonukleinsäuredesoxyribonukleinsäure
2.: normale rter mit nderz
3.: normale wörter mit sönderzäißchün
Code: Alles auswählen
<?php
$entry = 'aber aber';
$entry = ' ' . strip_tags(strtolower($entry)) . ' ';
$stopword_list = @file("language/lang_german/search_stopwords.txt");
//
// Filter out strange characters like ^, $, &, change "it's" to "its"
//
$drop_char_match = array('^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '-', '~', '+', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!');
$drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' , ' ', ' ', ' ', ' ', ' ', ' ');
for($i = 0; $i < count($drop_char_match); $i++)
{
$entry = str_replace($drop_char_match[$i], $drop_char_replace[$i], $entry);
}
if ( !empty($stopword_list) )
{
for ($j = 0; $j < count($stopword_list); $j++)
{
$stopword = trim($stopword_list[$j]);
if ( $mode == 'post' || ( $stopword != 'not' && $stopword != 'and' && $stopword != 'or' ) )
{
$entry = str_replace(' ' . trim($stopword) . ' ', ' ', $entry);
}
}
}
/*
// Original
$entry1 = preg_replace('/[ ]([\S]{1,2}|[\S]{21,})[ ]/',' ', $entry);
echo('1.: ' . $entry1 . '<br />');
// Code von Gerome phpBB.de
$entry2 = preg_replace('/(\b)([\S]{1,2}|[\S]{21,})(\b)/',' ', $entry);
echo('2.: ' . $entry2 . '<br />');
*/
// Code von Lese phpBB.com
$entry = str_replace('*', ' ', $entry);
$entry3 = preg_replace('/(?<= )([\S]{1,2}|[\S]{21,})(?= )/',' ', $entry);
echo('3.: ' . $entry3 . '<br />');
?>
D.h. der Code, der die Wörter per search_stopwords.txt filtern soll ist auch fehlerhaft.3.: aber
Code: Alles auswählen
$entry = preg_replace('/(?<= )' . trim($stopword) . '(?= )/', ' ', $entry);