[SOLVED] Whoever solves this for me gets a nice X-mas card!

This is a discussion on "[SOLVED] Whoever solves this for me gets a nice X-mas card!" within the PHP Forum section. This forum, and the thread "[SOLVED] Whoever solves this for me gets a nice X-mas card! are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Dec 3rd, 2007, 20:00
minute44's Avatar
Moderator
Join Date: Apr 2006
Location: Nottingham UK
Age: 24
Posts: 1,347
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to minute44
[SOLVED] Whoever solves this for me gets a nice X-mas card!

OK, I don't know if this is in the right forum so please excuse me if not. I have a problem. Well, not so much a problem, I want to do something and have no idea where to start.

If you look at minute44.com and scroll right down to the footer you will see my "Movie news at Empire" section.

At the moment I just update that when I feel like it but what I'd like it to do is pull the three most recent headlines from the news RSS feed: http://www.empireonline.com/rss/

I trust someone will have the knowledge to do this if not done it before.

Thanks in advance

Dan
Last Blog Entry: Annoying people.... (Jan 16th, 2008)
Reply With Quote

  #2 (permalink)  
Old Dec 3rd, 2007, 20:05
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Whoever solves this for me gets a nice X-mas card!

This is a mixture of RSS(XML) and PHP.
You need to grab the feed, then use an XML parser or regex to output stuff!
You can grab the feed with file_get_contents() or if they have leech protection, lookup CURL.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #3 (permalink)  
Old Dec 3rd, 2007, 20:12
minute44's Avatar
Moderator
Join Date: Apr 2006
Location: Nottingham UK
Age: 24
Posts: 1,347
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to minute44
Re: Whoever solves this for me gets a nice X-mas card!

Thanks alex but I know nothing of PHP at this point so can you make the process simple for me... I kinda get what you're saying it has to do but I can't code PHP.
Last Blog Entry: Annoying people.... (Jan 16th, 2008)
Reply With Quote
  #4 (permalink)  
Old Dec 3rd, 2007, 20:38
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Whoever solves this for me gets a nice X-mas card!

Well you won't be able to do this without PHP.
Maybe try customizing this tutorial? http://openkapow.com/blogs/support/a...from-Digg.aspx
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #5 (permalink)  
Old Dec 3rd, 2007, 20:50
SuperMember

SuperMember
Join Date: Jun 2007
Location: uk
Posts: 459
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Whoever solves this for me gets a nice X-mas card!

You could also take a look at this link.

http://www.webmasterworld.com/forum98/465.htm

Pat
Reply With Quote
  #6 (permalink)  
Old Dec 4th, 2007, 05:58
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Whoever solves this for me gets a nice X-mas card!

Moving to PHP forum I will have a shot at some code for you sometime tonight or tomorrow - if you haven't sorted it already.

Cheers
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #7 (permalink)  
Old Dec 4th, 2007, 07:40
minute44's Avatar
Moderator
Join Date: Apr 2006
Location: Nottingham UK
Age: 24
Posts: 1,347
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to minute44
Re: Whoever solves this for me gets a nice X-mas card!

Cheers matey
Last Blog Entry: Annoying people.... (Jan 16th, 2008)
Reply With Quote
  #8 (permalink)  
Old Dec 4th, 2007, 16:02
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Whoever solves this for me gets a nice X-mas card!

Okay as promised, this does it for you...

Now all you need to do is save this as a php file

PHP: Select all

<?php



function getLatestEmpireNews($numLinks 3$linkSeparator '<br />'
// send a value other than three to change the amount of links to output
// send something other than <br /> to put between the links, just use '' for nothing
{


// create an xml parser

$xmlReader xml_parser_create();


// to make this easier for all involved, parse the 
xml_parse_into_struct($xmlReaderfile_get_contents('http://www.empireonline.com/rss/rss.asp'), $values$indices);

// Now, what we should have is -- $values with an associative array of all xml tags that hold a reference to the location in the values array

// Having looked at the rss, each item has a title, a link and a description --  this will output the links with teh description as the link title
// The first one is just a link to empireonline so we can ignore

$output ''// set up the output

for ($i 1$i <= $numLinks$i++)
{
    
// cycle through the $values array and set up the links etc
    
$output .= '<a href="' $values[$indices['LINK'][$i]]['value'] . '" title="' $values[$indices['DESCRIPTION'][$i]]['value'] . '">' $values[$indices['TITLE'][$i]]['value'] . '</a>' $linkSeparator;
}

// by now we should have the desired number of links, simply return them and all is well

return $output;

}
?>

Then... on your page (that is .php or being interpreted as php by the server) you simply add this where you want the links to appear

PHP: Select all

<html stuff to here>

<?php
include('C:/the/absolute/path/to/the/file.php');
echo 
getLatestEmpireNews();
?>

<html stuff from here>
Hope that helps,

Cheers
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #9 (permalink)  
Old Dec 4th, 2007, 17:11
minute44's Avatar
Moderator
Join Date: Apr 2006
Location: Nottingham UK
Age: 24
Posts: 1,347
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to minute44
Re: Whoever solves this for me gets a nice X-mas card!

You're certainly on to something mate... it's not working though...

You on MSN...? Perhaps we can discuss getting this working.
Last Blog Entry: Annoying people.... (Jan 16th, 2008)
Reply With Quote
  #10 (permalink)  
Old Dec 4th, 2007, 17:15
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Whoever solves this for me gets a nice X-mas card!

It's working fine for me.. Are you pages .php on a compatible server? If yes, are you receiving and error messages on page or in your logs?
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #11 (permalink)  
Old Dec 4th, 2007, 17:19
minute44's Avatar
Moderator
Join Date: Apr 2006
Location: Nottingham UK
Age: 24
Posts: 1,347
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to minute44
Re: Whoever solves this for me gets a nice X-mas card!

look in the footer as it is now. view the source.
Last Blog Entry: Annoying people.... (Jan 16th, 2008)
Reply With Quote
  #12 (permalink)  
Old Dec 4th, 2007, 17:20
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Whoever solves this for me gets a nice X-mas card!

Luke, isn't this using PHP5 objects? Maybe he's on PHP4.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #13 (permalink)  
Old Dec 4th, 2007, 17:26
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Whoever solves this for me gets a nice X-mas card!

No, this is php4&5.

PHP is not able to open the file, something is refusing the connection.

Be sure that you have the path to the file correct.

Also, try adding the entire script as above into that page (at the top before <html> etc), then just drop the include part from the area you want to display it.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #14 (permalink)  
Old Dec 4th, 2007, 17:29
minute44's Avatar
Moderator
Join Date: Apr 2006
Location: Nottingham UK
Age: 24
Posts: 1,347
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to minute44
Re: Whoever solves this for me gets a nice X-mas card!

ok, I've changed the path but now I'm getting a parse error....

look now and tell me what you think
Last Blog Entry: Annoying people.... (Jan 16th, 2008)
Reply With Quote
  #15 (permalink)  
Old Dec 4th, 2007, 17:35
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Whoever solves this for me gets a nice X-mas card!

Have you removed the comments? Line 8 is nothing in the script I posted..

Be sure there is a { after the ) in the function declaration
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #16 (permalink)  
Old Dec 4th, 2007, 17:39
minute44's Avatar
Moderator
Join Date: Apr 2006
Location: Nottingham UK
Age: 24
Posts: 1,347
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to minute44
Re: Whoever solves this for me gets a nice X-mas card!

my line 8 is:


PHP: Select all

 function getLatestEmpireNews($numLinks 3$linkSeparator '<br />'
and all curly brackets seem in place.

the error I get is:


Parse error: syntax error, unexpected T_VARIABLE in /home/sites/minute44.com/public_html/wp-content/themes/juicy-20/empirenews.php on line 8
Last Blog Entry: Annoying people.... (Jan 16th, 2008)

Last edited by minute44; Dec 4th, 2007 at 17:44.
Reply With Quote
  #17 (permalink)  
Old Dec 4th, 2007, 17:48
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Whoever solves this for me gets a nice X-mas card!

What are the previous and next 2 lines?
Copy a chunk over please.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #18 (permalink)  
Old Dec 4th, 2007, 17:48
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Whoever solves this for me gets a nice X-mas card!

There is nothing wrong with that line.

Can you post the whole code as you are using it because something has gone wrong here The code is still working perfectly for me.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #19 (permalink)  
Old Dec 4th, 2007, 17:49
minute44's Avatar
Moderator
Join Date: Apr 2006
Location: Nottingham UK
Age: 24
Posts: 1,347
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to minute44
Re: Whoever solves this for me gets a nice X-mas card!

from the top it goes:

PHP: Select all

<?php





function getLatestEmpireNews($numLinks 3$linkSeparator '<br />'

// send a value other than three to change the amount of links to output

// send something other than <br /> to put between the links, just use '' for nothing

{





// create an xml parser



$xmlReader xml_parser_create();





// to make this easier for all involved, parse the 

xml_parse_into_struct($xmlReaderfile_get_contents('http://www.empireonline.com/rss/rss.asp'), $values$indices);



// Now, what we should have is -- $values with an associative array of all xml tags that hold a reference to the location in the values array



// Having looked at the rss, each item has a title, a link and a description --  this will output the links with teh description as the link title

// The first one is just a link to empireonline so we can ignore



$output ''// set up the output



for ($i 1$i <= $numLinks$i++)

{

    
// cycle through the $values array and set up the links etc

    
$output .= '<a href="' $values[$indices['LINK'][$i]]['value'] . '" title="' $values[$indices['DESCRIPTION'][$i]]['value'] . '">' $values[$indices['TITLE'][$i]]['value'] . '</a>' $linkSeparator;

}



// by now we should have the desired number of links, simply return them and all is well



return $output;



}

?>
Last Blog Entry: Annoying people.... (Jan 16th, 2008)
Reply With Quote
  #20 (permalink)  
Old Dec 4th, 2007, 17:53
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Whoever solves this for me gets a nice X-mas card!

Remove the comments maybe? Try this:
PHP: Select all


function getLatestEmpireNews($numLinks 3$linkSeparator '<br />') {

$xmlReader xml_parser_create();

..... 
add the rest in obviously
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
looking for credit card processing service CloudedVision E-Commerce and Business 9 Jun 9th, 2008 10:50
e-card help aslanandbeez PHP Forum 0 Apr 26th, 2008 15:53