Skip to content

Instantly share code, notes, and snippets.

@darkcolonist
Last active August 8, 2016 02:18
Show Gist options
  • Save darkcolonist/1bbac3f63fd21e7e34bb4061c7543449 to your computer and use it in GitHub Desktop.
Save darkcolonist/1bbac3f63fd21e7e34bb4061c7543449 to your computer and use it in GitHub Desktop.
pretty url dissection
<?php echo "it works!" ?>
<!-- use this url: http://localhost/url.php/id/123/age/20/gender/male/context/something/scholar2 -->
<hr />
<?php
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $actual_link;
$dissected_link = explode("/", $actual_link);
var_dump($dissected_link);
// echo $dissected_link[count($dissected_link)-1];
?>
<hr />
<?php
$my_keyword = "gender";
$my_value = null;
foreach ($dissected_link as $key => $one_link) {
if($one_link == $my_keyword){
if(!empty($dissected_link[$key+1]))
$my_value = $dissected_link[$key+1];
}
}
var_dump($my_value);
?>
<hr />
<?php
$our_segment = $dissected_link[count($dissected_link)-1];
echo $our_segment . "<br />";
// scholar1
echo "first sector: ".substr($our_segment, 0, 7) . "<br />";
echo "second sector: ".substr($our_segment, 7, 100) . "<br />";
// echo
?>
@darkcolonist
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment