I have a bit of code that extracts a string (I'm calling it a keyword) from a URL; it works fine:
Code: Select all
<?php
$keyword = "Aardvarks and Other Curious Animals"; //This term is assigned as the keyword if no keyword is provided
if ($_GET['q']) {
$keyword = (preg_replace("/\-/", " ", strip_tags(trim($_GET['q'])))); // strips white space, tags, converts to sentence case
// $keyword = preg_replace("/ Strip This Phrase/", "", $keyword); // This phrase is stripped out of the keyword
}
?>Code: Select all
<?php echo $keyword; ?>But I ALSO need to parse out just the first part of the URL string -- "Santa-Cruz,-California" to retrieve an existing file named "santa-cruz-california.php". This scenario will be repeated for a set of geographic names.
1. How do I extract just the first part of the URL? (we're probably talking about just one state if that helps)
2. How do I then build some code to include that like-named file on the page?