Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to change current url for link

    I have pages (created by a php file) in which I want to display the url of other pages, and links to that url.

    The url's are very similar. The url of the pages I have is (with varying numbers):
    Code:
    http://mydomain.com/index2.php?option=com_content&task=view&id=1&pop=1&page=0&Itemid=1
    The url I want to display and link to is (with corresponding id number):
    Code:
    http://mydomain.com/index.php?option=com_content&task=view&id=1
    In other words, I would like to have a bit of php code that takes the current url and strips out the '2' after "index" and strips '&pop=1&page=0&Itemid=1' out from after "&id=1". Then I can (hopefully) take the resulting url as value from that code to create a link echoing the value as location and as text. To clarify, and this may complicate things, I would like this script to work in all pages and therefore regardless of what the number of the id, pop, page or itemid is in the url.

    Unfortunately I have no clue how to do this. Is there anyone who could help me write this bit of php code?

    This would realy help me, so many many thanks in advance!

  • #2
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Are you looking for something like this?

  • #3
    New Coder
    Join Date
    Oct 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's not what I am looking for but I am glad to know about it, and thanks for responding!
    Trying to be more specific (at the risk of using terms wrongly because I don't know how to write code and can only understand some of the logic a bit):
    I think I need a function that gets the current url, makes a string out of it, changes that string, and turns the resulting string into the value of a variable, and then in the html link I would echo that variable as the href location and as the visible text between the opening and closing a tags.
    E

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    URL rewriting is your best bet, as what you're asking for is not feasible.

    Those parameters will have to be in your URL. Unless you move them to a session variable and never use them in a link.

  • #5
    New Coder
    Join Date
    Oct 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    After hours of researching, learning and trying I managed by writing my first bit of php code ($mosConfig_sitename is Joomla-specific but I think there is some php equivalent to it):

    Code:
    // taking current print version url and creating url of full article
    $articleprintversionurl = $_SERVER["REQUEST_URI"]; // getting part of the url to be edited
    $urlparttoexplode = substr($articleprintversionurl, 12);  // create part of url to be exploded
    list($optionpartofurl, $taskpartofurl, $idpartofurl, $poppartofurl, $pagepartofurl, $Itemidpartofurl) = explode("&", $urlparttoexplode); //explode into parts separated by &
    $articlefullversionurl = "http://www."; // building up full article url
    $articlefullversionurl .= $mosConfig_sitename;
    $articlefullversionurl .= "/index.php?";
    $articlefullversionurl .= $optionpartofurl;
    $articlefullversionurl .= "&";
    $articlefullversionurl .= $taskpartofurl;
    $articlefullversionurl .= "&";
    $articlefullversionurl .= $idpartofurl;
    
    Full page url: <a href="<?php echo $articlefullversionurl ?>"><?php echo $articlefullversionurl ?></a>
    It works, so not too bad for a lawyer if I say so myself


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •