Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here's an updated PHP script that extracts a random link from an RSS feed and redirects to that link:
- ```php
- <?php
- // RSS Feed Reader Code
- // RSS feed URL
- $rssFeedURL = 'http://example.com/wordpress/feed';
- // Fetch the RSS feed
- $rssFeed = simplexml_load_file($rssFeedURL);
- // Check if the RSS feed was loaded successfully
- if ($rssFeed !== false) {
- // Create an array to store the links
- $links = array();
- // Loop through each item in the feed
- foreach ($rssFeed->channel->item as $item) {
- // Get the article link
- $articleLink = $item->link;
- // Add the link to the array
- $links[] = $articleLink;
- }
- // Get a random link from the array
- $randomLink = $links[array_rand($links)];
- // Redirect to the random link
- header('Location: ' . $randomLink);
- exit();
- } else {
- // Error loading the RSS feed
- echo "Error loading RSS feed.";
- }
- ?>
- ```
- In this script, the RSS feed is fetched using `simplexml_load_file()`, and each article link is extracted and stored in the `$links` array. Then, a random link is selected using `array_rand()`. Finally, the script redirects the user to the randomly selected link using the `header()` function.
- Remember to replace `'http://example.com/wordpress/feed'` with the actual RSS feed URL from your WordPress blog.
- Please note that this script assumes that the RSS feed is in a valid format and that the links are present in the feed's items. Make sure to test the script with your specific RSS feed to ensure it works as expected.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement