Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You want to explode again your resulting string with <code>-</code> and keep the first element, something along the lines of </p> <pre><code>$url = $_SERVER['REQUEST_URI']; $check = end(explode('/local/',$url)); $check = current(explode('-', strtoupper($check))); echo $check; </code></pre> <p>This way, if the last part changes, you will still have your <code>CITYNAME</code> valid.</p> <p>Some more explanation, <code>explode</code> (documentation <a href="http://ca3.php.net/manual/en/function.explode.php" rel="nofollow">here</a>) will break the string into array elements, and it will break it using the first parameter, so in this case, passing <code>-</code> will create an array with 3 elements, <code>CITYNAME</code>, <code>FREE</code> and <code>SERVICES</code>. <code>current</code> (documentation <a href="http://ca3.php.net/manual/en/function.current.php" rel="nofollow">here</a>) 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 <code>explode('-', strtoupper($check))[0]</code> would also give you <code>CITYNAME</code>, and using <code>[1]</code> and <code>[2]</code> would give you <code>FREE</code> and <code>SERVICES</code>.</p> <p>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 <strong>constant</strong> 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 <code>"free-services"</code> with <code>""</code>. So I'm +1 his answer.</p> <p><strong>Edit 2:</strong> For some reason my answer was picked, for names with <strong>dashes</strong> you will need to do something similar to what cale_b suggested!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload