Last active
August 8, 2016 02:18
-
-
Save darkcolonist/1bbac3f63fd21e7e34bb4061c7543449 to your computer and use it in GitHub Desktop.
pretty url dissection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
?> |
Author
darkcolonist
commented
Aug 8, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment