I got my typical substandard script modification done the other day, simple job prepending a term to a search term for a specialty search. However as the script pages through the results it adds the term multiple times. so the first page is 'blue widgets' the second page is for 'blue blue widgets'
here's the place where the prepend is done..
$keywords = $cgi->param('keywords');
if( $keywords ne "" ) {
$keywords = "LOOPS" . " " . $keywords;
}
(where LOOPS is the keyword that keeps showing up)
is there a quick fix to this block that will make it so that if the term LOOPS has already been added to the $keyword, it won't add it again?
If you take pity on me this time, I promise not to buy bad programming in the future. I don't really wnat to go back to the moron who fixed it, just to have him try to charge me for the 'extra work.'
But I would rather include a logical AND to the if statement that means AND "LOOPS" is not already present in the keyword parameter. How would I do that?
$keywords = $cgi->param('keywords');
if( $keywords!= /LOOPS/) {
$keywords = "LOOPS" . " " . $keywords;
}
but that doesn't actually append the keyword. I thought this meant
if the keyword parameter doesn't contain a substring matching LOOPS
then add LOOPS to the string
It does solve the problem of the next result page, if I type in a search like 'LOOPS widgets'. But if I type in 'widgets' as I intend for users to do, it doesn't append the extra term. Please help.
I tried this
$keywords = $cgi->param('keywords');
if( $keywords!= /LOOPS/) {
$keywords = "LOOPS" . " " . $keywords;
}
You almost had it. You want a pattern match:
$keywords = $cgi->param('keywords');
if( $keywords!~ /LOOPS\s+/i) {
$keywords = "LOOPS" . " " . $keywords;
}
Not the change of the = to a tilde ~. The i makes it case insensitive, take it or leave it. The \s+ looks for a space following LOOPS, which should prevent it from matching on "LOOPS" in some other part of $keywords.