Jump to content


Photo

Remove part of string that is not in search query string


  • Please log in to reply
6 replies to this topic

#1 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 04 June 2006 - 03:26 PM


for some reason this works but not if the searchquery is the first letter onwards of the list1 or list2 arrays

can someone see what i can do to fix this so i foind the string should it be at the start of the lists

thanks





while ($row= mysql_fetch_row($result)) {
$array[]=$row;
}

// remove items that are not needed from arrays
for ($i = 0; $i < $num; $i++) {
$id = $array[$i][0];
$list1 = $array[$i][1];

$list1=explode("\r\n",$list1);
foreach($list1 as $key=>$value) {
// check for all lower case match

if(!strpos(strtolower($value), strtolower($search))) {
unset($fromwishlist[$key]);
}
}
$fromwishlist=implode("\r\n",$list1);

$list2 = $array[$i][2];
$list2=explode("\r\n",$list2);
foreach($list2 as $key=>$value) {
// check for all lower case match

if(!strpos(strtolower($value), strtolower($search))) {
unset($list2[$key]);
}
}
$list2=implode("\r\n",$list2);
}
Edit/Delete Message

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 04 June 2006 - 03:36 PM

I don't know exactly what it does, but based on your problem, I think:

(!strpos(strtolower($value), strtolower($search)))
won't work, because when strpos = 0 it is "considered" false.

You should use (strpos(strtolower($value), strtolower($search)) !== true).

PHP type comparison tables - Manual:
[a href=\"http://www.php.net/manual/en/types.comparisons.php\" target=\"_blank\"]http://www.php.net/manual/en/types.comparisons.php[/a]
~ D Kuang

#3 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 04 June 2006 - 03:52 PM

hi thanks that made sense and tried it but now it does not show any results


string = "cat\r\ndog\r\ncats"

search = "cat"

string would then = "cat\r\ncats" when the script runs


[!--quoteo(post=379911:date=Jun 4 2006, 04:36 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 4 2006, 04:36 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I don't know exactly what it does, but based on your problem, I think:

(!strpos(strtolower($value), strtolower($search)))
won't work, because when strpos = 0 it is "considered" false.

You should use (strpos(strtolower($value), strtolower($search)) !== true).

PHP type comparison tables - Manual:
[a href=\"http://www.php.net/manual/en/types.comparisons.php\" target=\"_blank\"]http://www.php.net/manual/en/types.comparisons.php[/a]
[/quote]

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 04 June 2006 - 03:54 PM

But did it show results before?

If yes, check again if you added the code properly.
If not, then you should re-do your code :P
~ D Kuang

#5 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 04 June 2006 - 03:57 PM

before the code i had it shows the results ok, but not if the first word was looked for, if string was

"cat\r\ndog\r\ncats"

and a search for "cat"

before string would = "cats" but should really be "cat\r\ncats"



[!--quoteo(post=379918:date=Jun 4 2006, 04:54 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 4 2006, 04:54 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
But did it show results before?

If yes, check again if you added the code properly.
If not, then you should re-do your code :P
[/quote]


#6 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 04 June 2006 - 04:17 PM

What happens now?
~ D Kuang

#7 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 04 June 2006 - 04:19 PM

ANSWER....


(!strstr(strtolower($value), strtolower($search)))



thanks for your help. could not have done it without it.

[!--quoteo(post=379932:date=Jun 4 2006, 05:17 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 4 2006, 05:17 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
What happens now?
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users