You need to just parse your url.
Let's say you have variable callde $url
storing your url as a string, if you just use parse_url() function here is what you get:
$url = "http://domain.com/.../pid=87dhdhjkh&tid=87ehjdhnjh";
$result = parse_url($url);
You will get this as an output:
Array (
[scheme] => http
[host] => domain.com
[path] => /.../pid=87dhdhjkh&tid=87ehjdhnjh
)
After that you can get path
from that array and parse it using parse_str() function:
parse_str($result['path'], $output);
print_r($output);
The output will be following:
Array
(
[/___/pid] => 87dhdhjkh
[tid] => 87ehjdhnjh
)
Now that array is stored in $output and you can retrieve value of tid
from it, which is what you needed:
print $output['tid'];
So to summarize here is everything you need:
$url = "http://domain.com/.../pid=87dhdhjkh&tid=87ehjdhnjh";
$result = parse_url($url);
parse_str($result['path'], $output);
print $output['tid'];
UPDATE:
This question and answer might be considered as duplicate of this: https://stackoverflow.com/a/11480852/2267244