Mailinglisten-Archive |
"Michael Krax (DE)" wrote:
>
> Hallo,
>
> scheinbar ein wiklich komplexes Thema *gehirnwurm bekomm* Also nochmal im
> Klartext. Ich suche:
>
> Eine lib die mir eine String in eine passendes (my)SQL Select für eine DB
> Volltextsuche verwandelt. Phrasen durch "", logische Ausdrücke mit + und -
> und möglichst Feldvorgaben/Einschränkungen über 'feldname:', AND / OR
> Auswahl
>
> Beispeil:
>
> +auto +haendler -toyato (Mode AND)
>
> wird zu:
>
> select links
> from keyword_table
> where keyword_field like '%auto%'
> and keyword_field like '%haendler%'
> and keyword_field not like '%toyota%'
Das ist ja nun was völlig anderes!
(1) Einfache Variante:
<?php
$text = "+auto +haendler -toyato";
preg_match_all("/([+-]{1})(.*?)[\s]+/s", $text, $regs, PREG_SET_ORDER);
var_dump($regs);
?>
(2) Komfortabel:
(1) Wegmatchen und anschließend noch:
<?php
$text = "+auto +'haendler ' -toyato";
preg_match_all("/([+-]{1})[\"']{1}(.*?)[\"']+/s", $text, $regs,
PREG_SET_ORDER);
var_dump($regs);
?>
Ulf
php::bar PHP Wiki - Listenarchive