Jump to content

Archived

This topic is now archived and is closed to further replies.

jasonc

Remove part of string that is not in search query string

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.