Jump to content

How to do a search form.


Sebolains

Recommended Posts

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

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.

Archived

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

×
×
  • 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.