Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

make if statement more organized

if (strpos($string1,"needle1") || strpos($string2,"needle2")) {


this can be a very long if statement

if there are more terms

is there a way to make more organized or maybe array
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You might also be able to use switch/case logic.  Helpful if you know more or less what your data looks like and you want to choose among several alternatives.  Search the PHP.net site for "switch" to find good examples.
This seems to be completely different if statements, mayb eyou can tell us more about the input and why you are searching for those values in separate strings ?
Avatar of rgb192

ASKER

I have a list of $email_address

bob bob@aol.com
mary smith mary@yahoo.com
george@gmail.com
<rick smith> rick@verizon.net


$email_address may/may not contain $name


function emailregex($str)
{
    // A REGULAR EXPRESSION TO FIND THE FROM-EMAIL ADDRESS
    $regex
    = '#'         // REGEX DELIMITER
    . '.*?'       // ANYTHING OR NOTHING
    . '\<'        // ESCAPED WICKET
    . '(.*?)'     // GROUP OF CHARACTERS WITH EMAIL ADDRESS
    . '\>'        // ESCAPED WICKET
    . '#'         // REGEX DELIMITER
    ;


    // ISOLATE THE FROM EMAIL ADDRESS
    preg_match($regex, $str, $matches);
    return $matches;
} 

Open in new window


there are some examples where function emailregex($str) does not parse out the email properly so I want to just use the whole address and strpos

if (strpos($email_to,$email_address) || strpos($email_from,$email_address)) {
...some examples where function emailregex($str) does not parse out...
SSCCE is your friend.  Please post the test data and show us what you want to get from it.  We are experts but not mind readers, and if you give us the data that you have for input and tell us the rules you want to use to acquire the output, we may very well be able to help you get from Point A to Point B.

Thanks and regards, ~Ray
Avatar of rgb192

ASKER

>>
...some examples where function emailregex($str) does not parse out...

I will look for the email from and email to headers where there are a different encoding than asci
Please post the test data and the expected results from each test sample, thanks.  It's not rocket science -- it's simple, plodding, repetitive testing.  And to give you a good answer we need to see the test data and the expected results.  (You need to see this, too!)
Avatar of rgb192

ASKER

I will post the data.
sorry for delay
Avatar of rgb192

ASKER

i think in array will work

rather than complex if statement


I still have not yet found the test data on circumstances where the parsing does not work