Jump to content

Recommended Posts


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
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]
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) [snapback]379911[/snapback][/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]
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) [snapback]379918[/snapback][/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]
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) [snapback]379932[/snapback][/div][div class=\'quotemain\'][!--quotec--]
What happens now?
[/quote]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.