Sebolains Posted September 22, 2008 Share Posted September 22, 2008 Hi I'm doing a simple search throughout a txt database. What I would like to know is what I have to put to say that a field 'contains' a variable previously assigned through a simple form. What I mean ois something like this: ... list($ID, $name, $description, $url)=explode('|',$line); If($name contains $sea){ echo' ... is it possible to replace the word 'contains' and make it work? I guess it should be something familiar to the "==" you would use if you want it to be equal, bue here I want it to CONTAIN it. Any possible help is welcome Link to comment https://forums.phpfreaks.com/topic/125380-how-to-do-a-search-form/ Share on other sites More sharing options...
JasonLewis Posted September 23, 2008 Share Posted September 23, 2008 Here is a method you may consider: $array = array("something", "foo", "bar", "ahhh"); if(in_array("foo", $array)){ echo "foo is in the array"; } It's hard to tell what you're exactly after. Say $name is 'Horsea' (lame), and $sea is 'sea'. If you want to check $name to see if the the variable $sea is inside it, you can use strpos(). $name = "Horsea"; $sea = "sea"; if(strpos($name, $sea) !== false){ echo "{$name} contains {$sea}"; } Hope that is of some help. Link to comment https://forums.phpfreaks.com/topic/125380-how-to-do-a-search-form/#findComment-648289 Share on other sites More sharing options...
F1Fan Posted September 23, 2008 Share Posted September 23, 2008 I would do it in the SELECT. SELECT * FROM table WHERE textfield ILIKE '%seach text%' Link to comment https://forums.phpfreaks.com/topic/125380-how-to-do-a-search-form/#findComment-648290 Share on other sites More sharing options...
JasonLewis Posted September 23, 2008 Share Posted September 23, 2008 It would depend whether the search was being performed on a database. Link to comment https://forums.phpfreaks.com/topic/125380-how-to-do-a-search-form/#findComment-648295 Share on other sites More sharing options...
Sebolains Posted September 23, 2008 Author Share Posted September 23, 2008 I think $name = "Horsea"; $sea = "sea"; if(strpos($name, $sea) !== false){ echo "{$name} contains {$sea}"; } Is exactly what I need. Thanks a million! PS: sea was supposed to be short for search ^^ Link to comment https://forums.phpfreaks.com/topic/125380-how-to-do-a-search-form/#findComment-648311 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.