Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8885053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:12:55+00:00 2026-06-14T21:12:55+00:00

Here’s my URL: http://www.mywebsite.com/local/cityname-free-services I am using $url = $_SERVER[‘REQUEST_URI’]; $check = end(explode(‘/local/’,$url)); $check

  • 0

Here’s my URL:

http://www.mywebsite.com/local/cityname-free-services

I am using

$url = $_SERVER['REQUEST_URI'];
$check = end(explode('/local/',$url));
$check = strtoupper($check);
echo $check;

to get the city name and capitalize it. However, when it echos I am getting this:

CITYNAME-FREE-SERVICES

when all I want to echo is this:

CITYNAME

What do I need to change in the code to just get the city name?

Also, some of the city names have dashes in them and I need those replaced with a blank space when echoed. What needs to be added for that? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:12:56+00:00Added an answer on June 14, 2026 at 9:12 pm

    You want to explode again your resulting string with - and keep the first element, something along the lines of

    $url = $_SERVER['REQUEST_URI'];
    $check = end(explode('/local/',$url));
    $check = current(explode('-', strtoupper($check)));
    echo $check;
    

    This way, if the last part changes, you will still have your CITYNAME valid.

    Some more explanation, explode (documentation here) will break the string into array elements, and it will break it using the first parameter, so in this case, passing - will create an array with 3 elements, CITYNAME, FREE and SERVICES. current (documentation here) will take the current position in the array and return this value, by default, the current position is on the first element. You can also index individual elements in your array, so explode('-', strtoupper($check))[0] would also give you CITYNAME, and using [1] and [2] would give you FREE and SERVICES.

    Edit: I didn’t see the dash part about city names. This complicates a bit the problem as your URL contains other dashes that you want to get rid of. If "-FREE-SERVICES" is constant and that’s always the part you want to get rid of, then doing what cale_b suggested is a good idea, which is to replace "free-services" with "". So I’m +1 his answer.

    Edit 2: For some reason my answer was picked, for names with dashes you will need to do something similar to what cale_b suggested!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
Here is my persistence.xml : <?xml version=1.0 encoding=UTF-8?> <persistence xmlns=http://java.sun.com/xml/ns/persistence xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd version=1.0>
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
here is my configuration: http://domain.com (obviously fictitious name...) hosted on a server running Apache
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here's the two scenarios. We are using a manually built xml soap request with
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here's the scenario: I have a local git repository that mirrors the contents of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.