Jump to content

file_get_contents How to target the url only with replace function ?


Semnomic

Recommended Posts

$rss = file_get_contents('www.somesite.com/rss');
$rssnew = str_replace('AAAA', 'BBB', $rss );

Hi got a sImple bit of code to replace text in the $rss,

 

how do i target the url only? as it is now its replacing all instances of "AAAA" in urls,text,links,image urls,etc.

 

 

Link to comment
Share on other sites

Since your second post wasn't any clearer than the first, I"ll try and understand.  You're saying that the contents of $res are not simply being "replace" but the links inside of $res are themselves being parsed and also being "replaced"?  That doesn't make sense to me.  Have you tried echoing the contents of $res to see that it is what you think it should be?

Link to comment
Share on other sites

OK lets try again.
 
I have a page on my site >>  rssrewriter.php
 
I visit this url >>  mysite.com/rssrewriter.php?somerssfeed.rss
 
I then use the code I posted to rewrite the rss and echo it out.
 
When it rewrites the rss it changes ALL instances of my "str_replace" throughout the whole outputted rss.
 
I want to limit the rewriting to only the url/ link - not the image,desc,etc. see below
 
Element Description Example
title The title of the item. Venice Film Festival Tries to Quit Sinking
link The URL of the item. http://nytimes.com/2004/12/07FEST.html
description The item synopsis. Some of the most heated chatter at the Venice Film Festival this week was about the way that the arrival of the stars at the Palazzo del Cinema was being staged.
author Email address of the author of the item. More. oprah\@oxygen.net
category Includes the item in one or more categories. More.
comments URL of a page for comments relating to the item. More. http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290
enclosure Describes a media object that is attached to the item. More.
guid A string that uniquely identifies the item. More. http://inessential.com/2002/09/01.php#a2
pubDate Indicates when the item was published. More. Sun, 19 May 2002 15:21:36 GMT
source The RSS channel that the item came from. More.

 

 

So i only want rewrite parts of the items in red not the whole thing.

Link to comment
Share on other sites

 

So i only want rewrite parts of the items in red not the whole thing.

 

str_replace will replace everything found in the supplied string, which in your case is the whole rss file.

 

Split it into parts so that you can change those parts that you want to, simplexml will help you to do that.

Link to comment
Share on other sites

str_replace will replace everything found in the supplied string, which in your case is the whole rss file.

 

Split it into parts so that you can change those parts that you want to, simplexml will help you to do that.

thanks i did see the last link you posted (same link) but was hoping there was some other way to do it like explode or something along those lines. I will try and work out simple xml as it is basically exploding it/doing exactly what i want. 

Link to comment
Share on other sites

Its a remote/dynamic file, it changes all the time and Im not in control of the original.

 

Im feeding a rss to a second site as if it was my own, spoofing the orig RSS.  But I need to rewrite the original urls so they fit my sites structure.

 

 

"-"s where very problematic and i needed to remove them but doing so removed them from image urls and at times also the html/text/article body messing up the new rss I was outputting.

 

I think im good now

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.