shiv pratap shiv pratap - 1 month ago 7
PHP Question

Get filename and variable name from url in php which exist in the url

I want to get filename with $_GET variable values from a url in php?

My url is http://dev.proprofs.com/helpdesk/admin/admin.php?t=email

I only want to retrieve the admin.php?t=email from the url?

How to do this? Please help.

Answer

Try this, use pathinfo

<?php
$filepath  = 'http://dev.proprofs.com/helpdesk/admin/admin.php?t=email';
$path_parts = pathinfo($filepath);

echo "dirname   : ".$path_parts['dirname']."\n";
echo "basename  : ".$path_parts['basename']."\n";
echo "extension : ".$path_parts['extension']."\n";
echo "filename  : ".$path_parts['filename']."\n";

?>

OUTPUT :

dirname   : http://dev.proprofs.com/helpdesk/admin
basename  : admin.php?t=email
extension : php?t=email
filename  : admin

DEMO