1
www.foo.com/Base/index.php/controller/method/ 

This is my url, I need to get only "controller/method" part out of it - is there any elegant way to achieve this?

parse_url($url, PHP_URL_PATH) 

This would be great, but it returns the whole "Base/index.php/controller/method" part.

3
  • 1
    explode the result ? Commented May 16, 2013 at 18:45
  • Exploding, removing...it's not really that elegant for me :P Commented May 16, 2013 at 18:46
  • @user2252786 Did you find an answer? Commented Nov 9, 2013 at 9:53

1 Answer 1

3
$url = "http://www.foo.com/Base/index.php/controller/method/"; $path = parse_url($url, PHP_URL_PATH); $parts = explode("/", $path); $index = array_search("index.php", $parts); $controller = $parts[$index+1]; $method = $parts[$index+2]; 

You did not provide any additional information about url format. But as example, you may use regular expressions with preg_match():

$url = "http://www.foo.com/Base/index.php/controller/method/"; preg_match ("/^.*Base\/index.php\/([a-zA-Z0-9_]*)\/([a-zA-Z0-9_]*)\/?/", $url, $data); $controller = $data[1]; $method = $data[2]; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.