dexter dexter - 2 months ago 8
PHP Question

how to get last id number from url using php

i want get last id from url,
i have url from text file like this

http://domain.com/..../pid=87dhdhjkh&tid=87ehjdhnjh


how to get output
87ehjdhnjh


i have this code

$file = fopen("file.txt", "r");
while(!feof($file)){
$line = fgets($file);
# do same stuff with the $line


$str = ($line);


if(preg_replace("/.+?\.*/", "$str", $m)){
echo $m[1] .'<br>' ;
}


but not work

Answer

Try this:

$input_value = 'http://domain.com/..../pid=87dhdhjkh&tid=87ehjdhnjh';
$last = explode('=', strstr($input_value, '&tid'));
echo $last[1];