SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need to manipulate a URL

    I have urls coming in from an RSS feed. I need to change them to add one thing. index.php should be index2.php. What is the best way to do this?

  2. #2
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please elucidate your request. are you trying to change index.php to index2.php? I'm not advanced as a php developer, that said, is masking an option or is that something totally different?
    Omnistar Etools offers Web Software Solutions for Businesses

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    preg_replace()?

    PHP Code:
    <?php
    echo preg_replace('~(?<=/)index.php~''index2.php''http://www.yourserver.com/index.php?foo=bar'); #http://www.yourserver.com/index2.php?foo=bar
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using the substr function to split up the string into usable segments.

    For instance:

    PHP Code:
    $string 'index.php';
    $bit_to_add '2';

    $newstring substr($string0, -4).$bit_to_add.substr($string, -4);

    echo 
    $newstring
    Hope this helps. Here is the link to this function: www.php.net/substr.

  5. #5
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $url str_replace('index.php''index2.php'$original_url); 
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  6. #6
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I got this done. The URL was actually being pulled in by another script and I had to figure out what it was doing and then insert the replace code. It all worked out a few minutes after 5, right on time to leave


Bookmarks

Posting Permissions

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