ted_chou12 Posted December 22, 2006 Share Posted December 22, 2006 For example, if this page's url address is "http://test.com/index.php", I wish to get the term "index" out of it.BTW I hope it can work for examples such as "index.php?id=page" or some php virtual pages.Thanks Ted. Link to comment https://forums.phpfreaks.com/topic/31595-get-the-current-page-name/ Share on other sites More sharing options...
kenrbnsn Posted December 22, 2006 Share Posted December 22, 2006 Take a look at the functions [url=http://www.php.net/parse_url]parse_url()[/url] and [url=http://www.php.net/path_info]path_info()[/url].Ken Link to comment https://forums.phpfreaks.com/topic/31595-get-the-current-page-name/#findComment-146446 Share on other sites More sharing options...
ted_chou12 Posted December 22, 2006 Author Share Posted December 22, 2006 I did this, inorder to get the query:echo parse_url($url, PHP_URL_QUERY);but nothing returns.BTW, I am sure that my current page is with a query. Link to comment https://forums.phpfreaks.com/topic/31595-get-the-current-page-name/#findComment-146453 Share on other sites More sharing options...
kenrbnsn Posted December 22, 2006 Share Posted December 22, 2006 How do you set the variable $url?Ken Link to comment https://forums.phpfreaks.com/topic/31595-get-the-current-page-name/#findComment-146454 Share on other sites More sharing options...
ted_chou12 Posted December 22, 2006 Author Share Posted December 22, 2006 this is how it looks like, correct me if I am wrong:$url = $_SERVER['PHP_SELF']; Link to comment https://forums.phpfreaks.com/topic/31595-get-the-current-page-name/#findComment-146456 Share on other sites More sharing options...
ted_chou12 Posted December 22, 2006 Author Share Posted December 22, 2006 okay, I finally got to here: [code]page=about[/code]but I want what is after the equal sign which is "about", how will I do that?BTW I tried explode() and it doesnt work, nothing appearswhich looks like this:foreach($query as $v) {list($arg,$que) = explode("=",$v);}can anyone give me any suggestions? thankyouTed. Link to comment https://forums.phpfreaks.com/topic/31595-get-the-current-page-name/#findComment-146471 Share on other sites More sharing options...
taith Posted December 22, 2006 Share Posted December 22, 2006 [code]$_GET['page'][/code] Link to comment https://forums.phpfreaks.com/topic/31595-get-the-current-page-name/#findComment-146474 Share on other sites More sharing options...
chiprivers Posted December 22, 2006 Share Posted December 22, 2006 this is probably a round-a-bout way of getting it and will need some validating:[code]<?php$url = "http://test.com/index.php";$url_x = explode('.',$url);$num = count($url_x);$x = $num - 2; $url_y = explode('/',$url_x[$x]);$num = count($url_y);$y = $num - 1;$file = $url_y[$y];?>[/code] Link to comment https://forums.phpfreaks.com/topic/31595-get-the-current-page-name/#findComment-146476 Share on other sites More sharing options...
ted_chou12 Posted December 22, 2006 Author Share Posted December 22, 2006 yeap get page does work, you made my life so simple now, but it doesnt seem to work for my function:[code]<?php$test = $_GET['page'];function menucurrent($que){if ($test == $que){echo "current";}}?><ul><li id="<?php menucurrent("index")?>"><a href="index.php">Home</a></li><li id="<?php menucurrent("archives")?>"><a href="index.html">Archives</a></li><li id="<?php menucurrent("downloads")?>"><a href="index.html">Downloads</a></li><li id="<?php menucurrent("services")?>"><a href="include.php?page=services">Services</a></li><li id="<?php menucurrent("support")?>"><a href="include.php?page=support">Support</a></li><li id="<?php menucurrent("about")?>"><a href="include.php?page=about">About</a></li> </ul>[/code]can anyone have a check please?thanksTED. Link to comment https://forums.phpfreaks.com/topic/31595-get-the-current-page-name/#findComment-146477 Share on other sites More sharing options...
ted_chou12 Posted December 22, 2006 Author Share Posted December 22, 2006 thanks. Link to comment https://forums.phpfreaks.com/topic/31595-get-the-current-page-name/#findComment-146478 Share on other sites More sharing options...
kenrbnsn Posted December 22, 2006 Share Posted December 22, 2006 The variable "$test" is not defined in the scope of the function. You can pass it in via the arguments, use the "global" statement in the function, or use $_GET['page'] in the function.Here's the code that would pass it.[code]<?php$test = $_GET['page'];function menucurrent($test,$que) { if ($test == $que) echo "current";}?><ul><li id="<?php menucurrent($test,"index")?>"><a href="index.php">Home</a></li><li id="<?php menucurrent($test,"archives")?>"><a href="index.html">Archives</a></li><li id="<?php menucurrent($test,"downloads")?>"><a href="index.html">Downloads</a></li><li id="<?php menucurrent($test,"services")?>"><a href="include.php?page=services">Services</a></li><li id="<?php menucurrent($test,"support")?>"><a href="include.php?page=support">Support</a></li><li id="<?php menucurrent($test,"about")?>"><a href="include.php?page=about">About</a></li> </ul>[/code]The others are left as an exercise for the reader. :)Ken Link to comment https://forums.phpfreaks.com/topic/31595-get-the-current-page-name/#findComment-146480 Share on other sites More sharing options...
ted_chou12 Posted December 22, 2006 Author Share Posted December 22, 2006 okay, thanks I understand, :D Link to comment https://forums.phpfreaks.com/topic/31595-get-the-current-page-name/#findComment-146481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.