Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8658001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:39:37+00:00 2026-06-12T15:39:37+00:00

I am trying to append all urls in a RSS feed with a extra

  • 0

I am trying to append all urls in a RSS feed with a extra string (like “/testing123” etc). The original url format from the RSS looks like this:

<link rel="alternate" type="text/html" href="http://website.com/item/name1/2162561"/>
<link rel="alternate" type="text/html" href="http://website.com/item/name2/2162435"/>

etc, I used regexp with str_replace in a for loop but i cannot seem to get it working correctly and if i use preg_replace i get errors. When i just echo out the urls with the string appended it appears how i want but when i use str_replace then the urls looks like this instead:

http://website.com/testing123/item/name1/2162561
http://website.com/testing123/item/name2/2162435

I need the urls with the append string at the end when they get replaced however like this:

<link rel="alternate" type="text/html" href="http://website.com/item/name1/2162561/testing123"/>
<link rel="alternate" type="text/html" href="http://website.com/item/name2/2162435/testing123"/>

The code i have is:

<?php 

// The append string
$append = '/testing123';

// The file
$file = "RSS.txt";

// Get the files contents
$contents = file_get_contents($file);

// The search pattern
$SearchPattern = '/href=["|\'](.[^"|\']+)/i';

// Run preg_match_all to grab all the Matches
preg_match_all( $SearchPattern, $contents, $Matches );

// Check to see if we have at least 1 match
$MatchCount = count($Matches[0]);

// If there is more than 1 match then run a for loop
if ( $MatchCount > 0 ) {
     for ( $i=0; $i < $MatchCount ; $i++ ) {

          $temp = $Matches[0][$i];
          echo $temp . $append . '<br />'; // Appears to work

          //$contents = str_replace($temp, $temp . $append, $contents); // But str_replace doesn't seem to work

          //preg_replace($temp, $temp . $append, $contents); // And using preg_replace gives a error

     };
};

echo $contents; // Display the contents

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:39:38+00:00Added an answer on June 12, 2026 at 3:39 pm

    This should work :

    <?php 
    
    // The append string
    $append = '/testing123';
    
    // The file
    $file = "RSS.txt";
    
    // Get the files contents
    $contents = file_get_contents($file);
    
    // The search pattern
    $SearchPattern = '/(<link .* href=".*)("\/>)/i';
    
    // Run preg_match_all to grab all the Matches
    preg_match_all( $SearchPattern, $contents, $matches );
    
    for($i=0;$i<count($matches[1]);$i++){
        echo $matches[1][$i].$append.$matches[2][$i]."\n";
    }
    
    ?>
    

    Basically, it filters the lines with regular expressions and extracts both sides of the index where you want to append text.

    It then concatenates it all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to append to a log file, using HTML tables format for
I'm trying to append a string of svg elements to the dom. This is
All I'm trying to do is return the long/lat values from the last know
I am trying to append an additional url chunk to an existing attribute and
I am trying to append an image to DIV and it works on ALL
I'm trying to append two JavaScript files to all pages in JIRA, following this
Im trying to first grab all the links from a page, when get the
I am trying to get all of the currency rates from this website and
I am trying to make a script to append all files ending with .hash
I am trying append some XML retrieved via a dojo.XHRGet to a dijit.layout.ContentPane .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.