user3690206
user3690206

Reputation: 37

How to get specific part of url?

I am working on search function which I want make my search more easier and I had store href inside my db. Therefore, I need to get specific part of current page url eg : abc.php. But now I only can get full url which is eg : http://abc_system/user/abc.php. Is it one of the solution is used substring?I am looking for some help. Hope you guys can help me out. Thanks in advanced.

This is my code which return url result:

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}

Upvotes: 0

Views: 1410

Answers (2)

Ranjith
Ranjith

Reputation: 2819

You need to use basename() function for get your filename from the URL string.

<?php
   $url = "http://google.com/sdfsaf/abcd.php";
   echo basename($url);  // It will returns abcd.php
?>

Demo

Upvotes: 1

Beep.exe
Beep.exe

Reputation: 1398

Use **parse_url()** if you want to split url to its components, For more info, Refer : http://www.php.net/manual/en/function.parse-url.php

Upvotes: 0

Related Questions