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?
| SitePoint Sponsor |





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?
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
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.
Try using the substr function to split up the string into usable segments.
For instance:
Hope this helps. Here is the link to this function: www.php.net/substr.PHP Code:$string = 'index.php';
$bit_to_add = '2';
$newstring = substr($string, 0, -4).$bit_to_add.substr($string, -4);
echo $newstring;





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





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