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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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']; Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
taith Posted December 22, 2006 Share Posted December 22, 2006 [code]$_GET['page'][/code] Quote Link to comment 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] Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 22, 2006 Author Share Posted December 22, 2006 thanks. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 22, 2006 Author Share Posted December 22, 2006 okay, thanks I understand, :D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.