Jump to content

[SOLVED] preg_match - best way to do multiple times


daveh33

Recommended Posts

This function is new to me - I have just found the below tutorial

 

if (preg_match("/php/i", "PHP is the web scripting language of choice.")) {
    echo "A match was found.";
} else {
    echo "A match was not found.";
}

 

To use this example.. Is it possible to search the text for 'language' & 'scripting' as well as 'php'?

 

Or would I just need to copy the code for each search I want to perform?

 

The goal is to write a script which searches a variable for several words & if any of them match, do 1 thing & if not - do another

OK - I see it needs to be in the below format: -

 

preg_match_all ( string pattern, string subject, array &matches [, int flags [, int offset]] )

 

I really dont understand how the string pattern works

 

I want to search for hello, hi or hey in $var

 

and then use that to complete an if statement for whether it has a found any matches or not

 

if someone can write this code for me it would be much appreicated

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.