Solved

make if statement more organized

Posted on 2013-02-05
9
156 Views
Last Modified: 2013-03-20
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
0
Comment
Question by:rgb192
  • 4
  • 4
9 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 38856202
Yes, you can gather the items together and use in_array()
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 38856206
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.
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 38856416
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 ?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:rgb192
ID: 38857829
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)) {
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 38857935
...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
0
 

Author Comment

by:rgb192
ID: 38903762
>>
...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
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 38903778
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!)
0
 

Author Comment

by:rgb192
ID: 38955039
I will post the data.
sorry for delay
0
 

Author Closing Comment

by:rgb192
ID: 39004934
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
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question