Skip to main content
added 64 characters in body
Source Link
revive
  • 863
  • 3
  • 15
  • 31

I need to find the value of a variable and use it to add a class to a div, based on a switch statement.

For example, my variable is $link and if $link has google.com IN IT at all, I need $class to equal 'google', if $link as yahoo.com IN IT at all, $class then needs to equal 'yahoo'

So, I need something like this, but I'm not sure how/or if to use preg_match or something to check and see if the $link variable has the value we are looking for in it - see 'case' text below:

    switch ($link) {
        case 'IF link has Google.com in it':
                        $class = 'google';
            break;

        case 'IF link has Yahoo.com in it':
                        $class = 'yahoo';
            break;

        default:
            # code...
            break;
}

OR if there is a better way to do this, please let me know :D Thanks

Also, I'm good with using an IF ELSE statement as well..

Thanks

I need to find the value of a variable and use it to add a class to a div, based on a switch statement.

For example, my variable is $link and if $link has google.com IN IT at all, I need $class to equal 'google', if $link as yahoo.com IN IT at all, $class then needs to equal 'yahoo'

So, I need something like this, but I'm not sure how/or if to use preg_match or something to check and see if the $link variable has the value we are looking for in it - see 'case' text below:

    switch ($link) {
        case 'IF link has Google.com in it':
                        $class = 'google';
            break;

        case 'IF link has Yahoo.com in it':
                        $class = 'yahoo';
            break;

        default:
            # code...
            break;
}

OR if there is a better way to do this, please let me know :D Thanks

I need to find the value of a variable and use it to add a class to a div, based on a switch statement.

For example, my variable is $link and if $link has google.com IN IT at all, I need $class to equal 'google', if $link as yahoo.com IN IT at all, $class then needs to equal 'yahoo'

So, I need something like this, but I'm not sure how/or if to use preg_match or something to check and see if the $link variable has the value we are looking for in it - see 'case' text below:

    switch ($link) {
        case 'IF link has Google.com in it':
                        $class = 'google';
            break;

        case 'IF link has Yahoo.com in it':
                        $class = 'yahoo';
            break;

        default:
            # code...
            break;
}

OR if there is a better way to do this, please let me know :D

Also, I'm good with using an IF ELSE statement as well..

Thanks

Source Link
revive
  • 863
  • 3
  • 15
  • 31

Help with a simple switch statement

I need to find the value of a variable and use it to add a class to a div, based on a switch statement.

For example, my variable is $link and if $link has google.com IN IT at all, I need $class to equal 'google', if $link as yahoo.com IN IT at all, $class then needs to equal 'yahoo'

So, I need something like this, but I'm not sure how/or if to use preg_match or something to check and see if the $link variable has the value we are looking for in it - see 'case' text below:

    switch ($link) {
        case 'IF link has Google.com in it':
                        $class = 'google';
            break;

        case 'IF link has Yahoo.com in it':
                        $class = 'yahoo';
            break;

        default:
            # code...
            break;
}

OR if there is a better way to do this, please let me know :D Thanks