hi first

i am actually working on a php search enginge, and have two problems. if someone could give me a hint i would be glad

ok - the first prob:
i can get a search string where the words are sepereated by commas easily into an array.
but if i try to do the same with google styled input i get mad
it's easy to seperate words by their spaces and explode them into an array, but how can i get the words combined by " into the same array?

you know, if someone searches for:
president "bill clinton" cigar

any ideas?

the second problem is probably simple - think i am just dumb:

i want to get a "dynamic" variable, which gains one digit in each "while" loop.

$variable1
$variable2
$variable3

but i can't get it to work (probably it works some way with $ - $$variable?)

thanks for reading
k@pixelfighters

ps: any tips for a more simple version of my whitespace replacement at the comma?

code snipplet here (just test style :-)

$string = "what, the,fuck , is , security?";
do {
$string = ereg_replace (" "," ", $string);
$string = ereg_replace (",",",", $string);
$string = ereg_replace (", ",",", $string);
$string = ereg_replace (", ",",", $string);
$string = ereg_replace (" ,",",", $string);
$string = ereg_replace (" ,",",", $string);
$stringreplace++;
}
$string = ereg_replace (" "," ", $string);
printf("$string<br><br>");
$sucheingabe = explode(",",$string);
$counter="0";
foreach ($sucheingabe as $words) {
$counter++;
$dynamic_variable???{$counter}???= "$words";
}

    Hello,
    Here are some possiblities. All problems are not thought out here, but maybe the direction will help...

    ===========
    You wrote:
    it's easy to seperate words by their spaces and explode them into an array, but how can i get the words combined by " into the same array?

    you know, if someone searches for:

    president "bill clinton" cigar


    Try:

    $string = "\"bill clinton\" cigar, monica";
    $arrayIn = explode(",", $string);


    Gives you the same as:

    $arrayCommas = array([0] => "\"bill clinton\" cigar", [1] => " monica");


    Then try:

    $arrayOut = array();

    foreach ($arrayCommas AS $plate1) {
    $plate1 = trim($plate1);

    if (strpos("\"", $plate1)) {
        $arrayQuotes = explode("\"", $plate1);
    
        foreach ($arrayQuotes AS $plate2) {
            $plate2 = trim($plate2);
            array_push($arrayOut, $plate2);
        } //end foreach
    } else {
        array_push($arrayOut, $plate1);
    } //end if

    } //end foreach

    print_r($arrayOut);


    Done:

    That may get you somewhere near an array where the "exact phrase" portions are saved. It's a fairly mechanical solution, so there is definitely something more elegant to be done. Note: I'm not completely sure on the argument order for strpos, so check that out.

    For the dynamic variable it goes something like:

    $variable = "variable" . ++n;
    $$variable = "someValue";

    For the whitespace replacement around commas try:

    $string = str_replace(array(" ,", " , ", ", "), ",", $string);

    -or-

    $string = ereg_replace("[ ][,]{1}[ ]", ",", $string);

    It's 4:30am...time to sleep...

    Good luck,
    Brandon

      Why not just expode by " and then by space and merge the two together?

        Write a Reply...