Sako Posted July 18, 2010 Share Posted July 18, 2010 Hi, I am new to Php. Let's say that my URLs look like: http://www.mywebsite.com/category/COMPUTERS/apple.php http://www.mywebsite.com/category/COMPUTERS/ibm.php http://www.mywebsite.com/category/COMPUTERS/dell.php I would like to have a variable defined as 'apple', 'ibm', 'dell'. The code I have below does not work well because these can have different number of characters... any help? $self = substr($_SERVER['PHP_SELF'], -8,4); echo $self; Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/208115-how-to-get-part-of-your-url/ Share on other sites More sharing options...
wildteen88 Posted July 18, 2010 Share Posted July 18, 2010 You could do $var = pathinfo($_SERVER['REQUEST_URI'], PATHINFO_FILENAME); echo $var; Link to comment https://forums.phpfreaks.com/topic/208115-how-to-get-part-of-your-url/#findComment-1087880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.