icon Learn how to get the most out of Surmunity - read our forum tips here! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » PHPsuexec » fopen - cURL help needed for new RSS cURL Newsfeed

PHPsuexec Information and tips

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old February 15th, 2008, 2:01 PM   #1 (permalink)
Registered User
Seasoned Poster
 
steelwidow's Avatar
 
Joined in Nov 2004
Lives in Columbus, Ohio
Hosted on Pass16
71 posts
Gave thanks: 1
Thanked 0 times
fopen - cURL help needed for new RSS cURL Newsfeed

Hi there. I've been using an rss script for a long time to import msn news to a website, but now I get this when using it: (according to surpass the fopen function has been disabled)

Quote:
Warning: fopen() [function.fopen]: URL file-access is disabled in the server configuration in /home/USERNAME/public_html/newsfeed/inc2/id_rss.inc on line 65

Warning: fopen(Live Search News: pharmaceutical) [function.fopen]: failed to open stream: no suitable wrapper could be found in /home/USERNAME/public_html/newsfeed/inc2/id_rss.inc on line 65
could not open XML input
Here's the RSS script:

PHP Code:

<?php

/*
Created by SW Designs
http://www.swdesigns.biz
*/

set_time_limit(0);

$file "http://search.msn.com/news/results.aspx?q=pharmaceutical&form=QBNR&format=rss&count=2";

$rss_channel = array();
$currently_writing "";
$main "";
$item_counter 0;


function 
startElement($parser$name$attrs) {
       global 
$rss_channel$currently_writing$main;
       switch(
$name) {
           case 
"RSS":
           case 
"RDF:RDF":
           case 
"ITEMS":
               
$currently_writing "";
               break;
           case 
"CHANNEL":
               
$main "CHANNEL";
               break;
           case 
"IMAGE":
               
$main "IMAGE";
               
$rss_channel["IMAGE"] = array();
               break;
           case 
"ITEM":
               
$main "ITEMS";
               break;
           default:
               
$currently_writing $name;
               break;
       }
}

function 
endElement($parser$name) {
       global 
$rss_channel$currently_writing$item_counter;
       
$currently_writing "";
       if (
$name == "ITEM") {
           
$item_counter++;
       }
}

function 
characterData($parser$data) {
    global 
$rss_channel$currently_writing$main$item_counter;
    if (
$currently_writing != "") {
        switch(
$main) {
            case 
"CHANNEL":
                if (isset(
$rss_channel[$currently_writing])) {
                    
$rss_channel[$currently_writing] .= $data;
                } else {
                    
$rss_channel[$currently_writing] = $data;
                }
                break;
            case 
"IMAGE":
                if (isset(
$rss_channel[$main][$currently_writing])) {
                    
$rss_channel[$main][$currently_writing] .= $data;
                } else {
                    
$rss_channel[$main][$currently_writing] = $data;
                }
                break;
            case 
"ITEMS":
                if (isset(
$rss_channel[$main][$item_counter][$currently_writing])) {
                    
$rss_channel[$main][$item_counter][$currently_writing] .= $data;
                } else {
                    
$rss_channel[$main][$item_counter][$currently_writing] = $data;
                }
                break;
        }
    }
}

$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");
if (!(
$fp fopen($file"r"))) {
    die(
"could not open XML input");
}

while (
$data fread($fp4096)) {
    if (!
xml_parse($xml_parser$datafeof($fp))) {
        die(
sprintf("XML error: %s at line %d",
                    
xml_error_string(xml_get_error_code($xml_parser)),
                    
xml_get_current_line_number($xml_parser)));
    }
}
xml_parser_free($xml_parser);

// output HTML
// print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . "</div>"); 

if (isset($rss_channel["ITEMS"])) {
    if (
count($rss_channel["ITEMS"]) > 0) {
        for(
$i 0;$i count($rss_channel["ITEMS"]);$i++) {
            if (isset(
$rss_channel["ITEMS"][$i]["LINK"])) {
            print (
"\n<div class=\"itemtitle\"><a target=blank href=\"" "go.php?url=" $rss_channel["ITEMS"][$i]["LINK"] . "\">" $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
            } else {
            print (
"\n<div class=\"itemtitle\">" $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
            }
             print (
"<div class=\"itemdescription\">" $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />");         }
    } else {
        print (
"<b>There are no articles in this feed.</b>");
    }
}

?>
I asked Surpass why it wasn't working and they said because they disabled the f_open and I should use cURL for security reasons. Can anyone tell me what lines to change in this script to get it to work?

I think it's actually this area...

PHP Code:
$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");
if (!(
$fp fopen($file"r"))) {
    die(
"could not open XML input"); 
Also within this little script I think we need to declare the path to cURL?????

Any help would be appreciated. Hey if we can get this to work this is a nice little script to share with others so they can easilly get RSS feeds to work on their sites as well.

If you know of another script that would work in it's place, please advise.

Thanks in advance for your help.
__________________
Pass16
http://www.swdesignshosting.com
steelwidow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old February 15th, 2008, 2:11 PM   #2 (permalink)
Surpass Developer
On a golden path...
 
Mark's Avatar
 
Joined in Jan 2004
Lives in Florida
Hosted on decc.surpasshosting.com
359 posts
Gave thanks: 7
Thanked 58 times
Blog Entries: 1
Replace this

PHP Code:
$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");
if (!(
$fp fopen($file"r"))) {
    die(
"could not open XML input");
}

while (
$data fread($fp4096)) {
    if (!
xml_parse($xml_parser$datafeof($fp))) {
        die(
sprintf("XML error: %s at line %d",
                    
xml_error_string(xml_get_error_code($xml_parser)),
                    
xml_get_current_line_number($xml_parser)));
    }

with this

PHP Code:
$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");

$ch curl_init();
curl_setopt($chCURLOPT_URL$file);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
$xmldata curl_exec($ch);
curl_close($ch);

$xmldata split("\n",$xmldata);

foreach (
$xmldata as $data) {
    if (!
xml_parse($xml_parser$data)) {
        die(
sprintf("XML error: %s at line %d",
                    
xml_error_string(xml_get_error_code($xml_parser)),
                    
xml_get_current_line_number($xml_parser)));
    }

I *think* that should work, but i'm not totally sure because I haven't done too much php+xml
__________________
Mark
Surpass Hosting Developer
sɹnoʎ uɐɥʇ ɹǝʇʇǝq sı bıs ʎɯ
Mark is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks Mark for this great post!
steelwidow (February 16th, 2008)
Old February 16th, 2008, 1:25 PM   #3 (permalink)
Registered User
Seasoned Poster
 
steelwidow's Avatar
 
Joined in Nov 2004
Lives in Columbus, Ohio
Hosted on Pass16
71 posts
Gave thanks: 1
Thanked 0 times
Talking You are a cURL GOD!

Thank you so much! You are the master of cURL! (In my book anyhow.)

The newsfeed works.

Attached is the entire script for anyone that would like to use it. Mark I've thanked you in the read me file.

Attached Files
File Type: zip cURL_Newsfeed_Script.zip (2.8 KB, 27 views)
__________________
Pass16
http://www.swdesignshosting.com
steelwidow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may 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