Hi there, OK so I'm comfortable with how str_replace works I think, but I need to put it into action on a live environment. I've got a live XML feed that I provide to our partners that sits behind a username/password. I've got a list of english terms that I need to translate for one partner in particular, along with their translated terms. The feed doesn't sit on a server that I have any control over at all. So I figure I'll need to use wget to grab the file, then str_replace to search for the strings that need replacing before I republish on our side and give it to our user. It's a live feed, so I need to be checking for changes every 30 seconds or so.Ideally I'm looking for something relatively off-the-shelf that I can use for this - I understand I might not be able to do everything I'm looking for in one go here, but if anyone has any ideas of where I can start with this it'd be massively appreciated - Id really rather not start off from scratch here. Has anyone got any experience with this kind of thing that might be able to offer some advice? Thanks in advance.
From what I can tell that is the way you would need to do it. Every 30 seconds seems a bit extreme to me, I'd go for a minute at the minimum
Thanks for that - please I've at least got the principal right, heh. Do you know of anything out there that's already been written & might make my life a little easier? While I think I'll be able to do it, it'll take me an age without the starting blocks.
Not really that I can think of. I don't see why this is so difficult if it's just replacing words with other words
Well it's not hard to do each of those tasks individually, it's linking them together that I'm having the problem with. So I started off with <?php system('wget --user=USER --password=PASS http://example.com/feed.xml -O livefeed.xml'); ?> So that wgets the feed & saves it as a file called livefeed.xml Awesome. But I figure I need to save the contents of the feed as a variable, so I've done this: <?php $feeddata = system('wget --user=USER --password=PASS http://example.com/feed.xml'); ?> Now there are a few things I need to replace as I'd mentioned, but just to get going I'm going to look for just one of the strings that need replacing: <?php $feeddata = system('wget --user=USER --password=PASS http://example.com/feed.xml'); $replaceone = str_replace("STRING", "REPLACESTRING", $feeddata); echo $replaceone; ?> *Obviously* this doesn't work... Can you tell I'm not all that good at this? Really I need to know how to link that variable I created with the str_replace function, then have that save in the file that would have been created by wget. I'm also conscious that I should be doing this using an array rather than multiple instances of str_replace as that's just bound to get messy. Thanks for the help so far.
OK this works: <?php system('wget --user=XXX --password=XXX http://example.com.xml -O livefeed.xml'); $feeddata = file_get_contents("livefeed.xml"); $fp = fopen("livefeed.xml","w"); $feeddata = str_replace("STRING1", "REPLACESTRING", $feeddata); $feeddata = str_replace("STRING1", "REPLACESTRING", $feeddata); fwrite($fp,$feeddata); fclose($fp); ?> Ta!
Use curl to get the file (XML) content ( and you can authenticate using CURL aswell) then replace the data inside and fwrite with new content