March 21, 2013 asvignesh 0Comment

Still many people using query string / get method for their URL to getting the value from the user , but these query strings are not Search engine friendly , To create a searchengine friendly url you can make use of URI segments Instead we can use like

I explain you how to fetch the URI segments

Here is a set of two php functions that I use regularly to quickly get a specific URI segment or return all segments available.

These are very helpful if you have written or are writing your own custom SEF urls

function getUriSegments() {
   return explode(“/”, parse_url($_SERVER[‘REQUEST_URI’], PHP_URL_PATH));
function getUriSegment($n) {
   $segs = getUriSegments();
   return count($segs)>0&&count($segs)>=($n-1)?$segs[$n]:”; //if uri segment us available then return uri else return ‘null’
// if the url is
echo getUriSegment(1); //returns foo
echo getUriSegment(2); //returns bar
var_dump(getUriSegments()); //returns array(0=>’foo’, 1=>’bar’, 2=>’wow’)

6+ years of experience in building data protection, copy data management and storage management applications, automation software and plugins for private and public clouds

Disclaimer :

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. my thoughts and opinions change from time to time… This weblog is intended to provide a semi-permanent point in time snapshot and manifestation of the various memes running around my brain, and as such any thoughts and opinions expressed within out-of-date posts may not the same, nor even similar, to those I may hold today.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.