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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.