Hello, I am trying to convert a URL string into something that would be easier for me to read.

My PHP with currently just output a link directly from the DB, such as index.php?subj=6#121213

Subject 6 is "Events" and the ID is "121213"

I would like to convert the link from
Events #121213
But I also have links like cat=2 and pg=1

So here's what I need

A function that...

1. Will be able to tell is link is for a category (cat), subject (subj), or page (pg)
2. Grab real name of the type from DB (subj=6 -> Events, cat=1 -> Home), but I already have a function that does this part
3. Get the 6 digit (always will be 6 digits) ID number from link to display.

I have looked through substr, strpos, and preg_match, but I cannot seem to figure out the best way to pull off [if($link contains "?subj="){connect to subject table}]

Thanks for help.