1
$url = $_SERVER['REQUEST_URI'];
$url = basename($url).PHP_EOL;

switch ($url) {
    case 'digital-marketing-and-seo':
        $new_url = "Digital Marketing & SEO";
        break;
    case 'websites-digital-destinations':
        $new_url = "Websites & Digital Destinations";
        break;
    case 'brand-identity-evolution':
        $new_url = "Brand Identity & Evolution";
        break;
    case 'strategy-consulting':
        $new_url = "Strategy & Consulting";
        break;
    case 'government-universities':
        $new_url = "Government & Universities";
        break;
    case 'hospitality-travel':
        $new_url = "Hospitality & Travel";
        break;
    case 'architecture-engineering':
        $new_url = "Architecture & Engineering";
        break;
    case 'wine-spirits':
        $new_url = "Wine & Spirits";
        break;
    default:
        $new_url = '';
        echo 'default derp';
}

So I have this block of code and it will not work for me. The url can say exactly what is in the case and it will default. I'm trying to get url structures to build out a shortcode and I need it to match what is entered.

I determined that if I enter just add a variable for a string for $url = 'brand-identity-evolution'; The switch works. I made sure it's a string with is_string function and can't figure out why this isn't working.

1 Answer 1

3

You added a PHP_EOL at the end of the URL, so all of your cases will fail because you're not checking for that. Remove your PHP_EOL and you'll be fine.

Sign up to request clarification or add additional context in comments.

3 Comments

Awesome! It's been a long day. Thanks.
You're welcome. Please be sure to mark this as the answer if it fixes your issue
Yeah it wouldn't let me last night due to the quickness of the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.