How to retrieve url ???

Discussion in 'HTML & Website Design' started by rrn, Apr 8, 2009.

  1. #1
    my website is in php , sql....
    www.test.com/index.php..i want to retrieve ' index.php' from the url into an html page ... and use it as a link...

    ie if i am on www.test.com/site.php. ...i want to retrieve only the ' site.php' of the url....
    how can it b done?? pls hellp........
     
    rrn, Apr 8, 2009 IP
  2. Oxi

    Oxi Peon

    Messages:
    78
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can do this in php. To retrieve strings from url's, make use of php predefined variables. A list is over here at: http://uk2.php.net/reserved.variables

    To get the page from the url you can simply use this script

    $pagename=pathinfo($_SERVER["PHP_SELF"]);
    $pagename=$pagename["basename"];

    and then echo the variable pagename like so:

    echo $pagename;

    There are many useful variables already built in, ensure you make full use of them ;)
     
    Oxi, Apr 8, 2009 IP
  3. rrn

    rrn Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank u...

    i am able to retrieve the base of url using

    $pagename=pathinfo($_SERVER["PHP_SELF"]);
    $pagename=$pagename["basename"];

    but

    i want to use the value of $pagename in place of "----" in the below shown line of code......

    <a href="-----"><img src="arabic.gif" border="0" alt="" /></a>

    how can i do it???pls help.........
     
    rrn, Apr 8, 2009 IP
  4. Oxi

    Oxi Peon

    Messages:
    78
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you wanted to do that then why did you need the specific page name? :S You can use it like this though:
    <a href="<?php $pagename ?>"><img src="arabic.gif" border="0" alt="" /></a>
     
    Oxi, Apr 8, 2009 IP
  5. rrn

    rrn Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank u for ur help...

    i tried doing that...but its not working...

    <a href="<?php $pagename ?>"><img src="arabic.gif" border="0" alt="" /></a>
    when i use this code... it is directing only to the index.php of the site..

    when i am in the site.php or whatever page i am viewing then and clicking the link it is directing to index.php

    pls help......
     
    rrn, Apr 8, 2009 IP