PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
But what i would like to do is instead of pulling out that link, i would like to pull out the printer friendly link which is contained in the article, so for this page i would like to display
$rss_document = simpleXML_load_file('http://www.medicalnewstoday.com/rss/allergy.xml');
/Loop through each item in document
foreach($RSS_doc->channel->item as $RSS_item) {
//The variable $RSS_item will hold a different item for each loop
//Write the current item's title to the screen in HTML tags
echo "<h3>$RSS_item->title</h3>";
echo "<a href='".$RSS_item->link."'>{$RSS_item->link}</a><br />";
echo "<b>$RSS_item->pubDate</b><br />";
echo "$RSS_item->description<br /><br />";
foreach($RSS_doc->channel->item as $RSS_item) {
//The variable $RSS_item will hold a different item for each loop
//Write the current item's title to the screen in HTML tags
echo "<h3>$RSS_item->title</h3>";
$url = "http://www.medicalnewstoday.com/printerfriendlynews.php?newsid=" . substr("$RSS_item->link", 41, -4);
echo "<a href='$url'>$url</a><br />";
echo "<b>$RSS_item->pubDate</b><br />";
echo "$RSS_item->description<br /><br />";
}
foreach($RSS_doc->channel->item as $RSS_item) {
//The variable $RSS_item will hold a different item for each loop
//Write the current item's title to the screen in HTML tags
echo "<h3>$RSS_item->title</h3>";
$url = "http://www.medicalnewstoday.com/printerfriendlynews.php?newsid=" . substr("$RSS_item->link", 41, -4);
echo "<a href='$url'>$url</a><br />";
echo "<b>$RSS_item->pubDate</b><br />";
echo "$RSS_item->description<br /><br />";
}
Since there is no mention of a printer friendly link in the RSS but you do have the link in the RSS, you could do a simple string replacement. You want to make http://www.medicalnewstoday.com/articles/133241.php
Harry190091 wrote:thanks. What does the 41, -4 mean please ?
41 is the position where the numbers begin. Go ahead and count (remember that the first character is 0, not 1).
The third argument is the length of the string to capture: -X means the rest of the string except the last X characters.
Everah wrote:Since there is no mention of a printer friendly link in the RSS but you do have the link in the RSS, you could do a simple string replacement. You want to make http://www.medicalnewstoday.com/articles/133241.php
Harry190091 wrote:thanks. What does the 41, -4 mean please ?
41 is the position where the numbers begin. Go ahead and count (remember that the first character is 0, not 1).
The third argument is the length of the string to capture: -X means the rest of the string except the last X characters.
From your code help, it is almost displaying correctly, but not picking up the newsid number, It is displaying this below.
Anti-Allergy Vaccines To Help People With Asthma
http://www.medicalnewstoday.com/articles/133241.php
http://www.medicalnewstoday.com/printer ... sid=133241
Wed, 17 Dec 2008 03:00:00 PST
Research funded by Asthma UK has led to the development of a vaccine treatment that can prevent asthma-like symptoms in mice. Dr Noble and his team at King's College London have been studying allergic mechanisms in mice and investigating whether it is possible to regulate the immune system's response to potential allergic triggers.
Anti-Allergy Vaccines To Help People With Asthma
http://www.medicalnewstoday.com/articles/133241.php
http://www.medicalnewstoday.com/printer ... sid=133241
Wed, 17 Dec 2008 03:00:00 PST
Research funded by Asthma UK has led to the development of a vaccine treatment that can prevent asthma-like symptoms in mice. Dr Noble and his team at King's College London have been studying allergic mechanisms in mice and investigating whether it is possible to regulate the immune system's response to potential allergic triggers.
Is the second url not what you are after?
yes the 2nd link is what i am after. I would like to only show that as a clickable link, and not show the /articles/ link at all.
Everah wrote:The code I posted gives you everything you need to get what you want. Look at it closely and see if you can't figure out how to get at what you want.
My fault , I was sticking the $printer = string outside the loop. Now i have it inside the loop it is working fine.