caspert_ghost Posted May 4, 2007 Share Posted May 4, 2007 Hello all, I have an rss script that works fine on my test server but when I upload to a live server I get errors. my test server is using php 5.2.1 and my live server is running php 4.4.6 here is the code: rss_feeds.php <?php class OnlyHellRssFeed { private $nr_news= 10; private $rss_channel = array(); private $currently_writing = ""; private $main = ""; private $item_counter = 0; private $template; private $feedname; private $url; function __construct($feedname, $url) { $this->feedname = $feedname; $this->url = $url; } function startElement($parser, $name, $attrs) { switch($name) { case "RSS": case "RDF:RDF": case "ITEMS": $this->currently_writing = ""; break; case "CHANNEL": $this->main = "CHANNEL"; break; case "IMAGE": $this->main = "IMAGE"; $this->rss_channel["IMAGE"] = array(); break; case "ITEM": $this->main = "ITEMS"; break; default: $this->currently_writing = $name; break; } } function endElement($parser, $name) { $this->currently_writing = ""; if ($name == "ITEM") { $this->item_counter++; } } function characterData($parser, $data) { if ($this->currently_writing != "") { switch($this->main) { case "ITEMS": if (isset($this->rss_channel[$this->main][$this->item_counter][$this->currently_writing])) { $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] .= $data; } else { //print ("rss_channel[$main][$item_counter][$currently_writing] = $data<br>"); $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] = $data; } break; } } } function get_data(&$template) { $xml_parser = xml_parser_create(); xml_set_element_handler( $xml_parser, array($this, 'startElement'), array($this, 'endElement') ); xml_set_character_data_handler( $xml_parser, array($this, 'characterData') ); $data = self::curl_string($this->url); xml_parse($xml_parser,$data); xml_parser_free($xml_parser); // putting in array $news=array(); if (isset($this->rss_channel["ITEMS"])) { if (count($this->rss_channel["ITEMS"]) > 0) for($i = 0;$i < count($this->rss_channel["ITEMS"]);$i++) $news[]=$this->rss_channel["ITEMS"][$i]; } $c=0; foreach($news as $key=>$val) { if($c<$this->nr_news) { $template->assign_block_vars($this->feedname, array( 'LINK' => $val['LINK'], 'TITLE' => $val['TITLE'], 'DESC' => $val['DESCRIPTION']) ); } $c++; } } private static function curl_string ($url,$user_agent='Mozilla 4.0'){ $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_TIMEOUT, 120); $result = curl_exec ($ch); curl_close($ch); return $result; } } ?> rss_feedlist.php <?php /* setup: 'variablename' => 'RSS URL' example: 'oneup' => 'http://www.1up.com/rss?x=1', the variable name is used in the html file to loop thru and create the data, take a look at the first feed in the rss_feeds.html file - see how ign is used */ $feeds = array( 'mtgbks' => 'http://www.wizards.com/rss.asp?x=books', 'mtgdnd' => 'http://www.wizards.com/rss.asp?x=dnd', 'mtgd20' => 'http://www.wizards.com/rss.asp?x=d20modern', 'mtgebr' => 'http://www.wizards.com/rss.asp?x=eberron', 'mtgfr' => 'http://www.wizards.com/rss.asp?x=forgottenrealms', 'mtgmtg' => 'http://www.wizards.com/rss.asp?x=magic', 'mtgswrpg' => 'http://www.wizards.com/rss.asp?x=starwars-rpg', ); foreach ($feeds as $feed_name => $url) { $feed = new OnlyHellRssFeed($feed_name, $url); $feed->get_data($template); } ?> on my test server this works fine. on my live server I get an error: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/admin/public_html/bb3portal/block/rss_feeds.php on line 9 any help is appreciated, thank you Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/ Share on other sites More sharing options...
ToonMariner Posted May 4, 2007 Share Posted May 4, 2007 have a look to see if you live server has short tags enabled in the php.ini file. Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245182 Share on other sites More sharing options...
caspert_ghost Posted May 4, 2007 Author Share Posted May 4, 2007 short_open_tag On On this is the same on both servers. Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245185 Share on other sites More sharing options...
caspert_ghost Posted May 4, 2007 Author Share Posted May 4, 2007 After searching around I found that php 5 added some new functionality to the code. It turns out that maybe the code I have is not php 4 compatible. Could you look see where the problem may be. **some have said it may be the "private" code... anyone? Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245279 Share on other sites More sharing options...
taith Posted May 4, 2007 Share Posted May 4, 2007 it would be something with the private $var;... try changing them to private $var="";? Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245282 Share on other sites More sharing options...
caspert_ghost Posted May 4, 2007 Author Share Posted May 4, 2007 it would be something with the private $var;... try changing them to private $var="";? change "private" to $var= or add $var= ie: $var=$nr_news= 10; or private $var=$nr_news= 10; Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245296 Share on other sites More sharing options...
caspert_ghost Posted May 5, 2007 Author Share Posted May 5, 2007 The above rsss_feeds.php is not php 4 compatible. anyone here can help me make it compatible? I have changed all of the "private" to var, but still get errors. thank you. Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245858 Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 __construct is new to 5, you have to make your constructor the same name as the class... Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245866 Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 i.e. function OnlyHellRssFeed Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245869 Share on other sites More sharing options...
caspert_ghost Posted May 5, 2007 Author Share Posted May 5, 2007 so function OnlyHellRssFeed NOT class OnlyHellRssFeed Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245891 Share on other sites More sharing options...
caspert_ghost Posted May 5, 2007 Author Share Posted May 5, 2007 code as it is now (this site wont allow edits so I must create new post ) rss_feeds.php <?php // rss_feeds.php written by Static & Penagate @ http://staticfx.com // this file goes in the /bb3portal/block/ directory class OnlyHellRssFeed { var $nr_news=10; var $rss_channel = array(); var $currently_writing = ""; var $main = ""; var $item_counter = 0; var $template; var $feedname; var $url; function __construct($feedname, $url) { $this->feedname = $feedname; $this->url = $url; } function startElement($parser, $name, $attrs) { switch($name) { case "RSS": case "RDF:RDF": case "ITEMS": $this->currently_writing = ""; break; case "CHANNEL": $this->main = "CHANNEL"; break; case "IMAGE": $this->main = "IMAGE"; $this->rss_channel["IMAGE"] = array(); break; case "ITEM": $this->main = "ITEMS"; break; default: $this->currently_writing = $name; break; } } function endElement($parser, $name) { $this->currently_writing = ""; if ($name == "ITEM") { $this->item_counter++; } } function characterData($parser, $data) { if ($this->currently_writing != "") { switch($this->main) { case "ITEMS": if (isset($this->rss_channel[$this->main][$this->item_counter][$this->currently_writing])) { $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] .= $data; } else { //print ("rss_channel[$main][$item_counter][$currently_writing] = $data<br>"); $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] = $data; } break; } } } function get_data(&$template) { $xml_parser = xml_parser_create(); xml_set_element_handler( $xml_parser, array($this, 'startElement'), array($this, 'endElement') ); xml_set_character_data_handler( $xml_parser, array($this, 'characterData') ); $data = self::curl_string($this->url); xml_parse($xml_parser,$data); xml_parser_free($xml_parser); // putting in array $news=array(); if (isset($this->rss_channel["ITEMS"])) { if (count($this->rss_channel["ITEMS"]) > 0) for($i = 0;$i < count($this->rss_channel["ITEMS"]);$i++) $news[]=$this->rss_channel["ITEMS"][$i]; } $c=0; foreach($news as $key=>$val) { if($c<$this->nr_news) { $template->assign_block_vars($this->feedname, array( 'LINK' => $val['LINK'], 'TITLE' => $val['TITLE'], 'DESC' => $val['DESCRIPTION']) ); } $c++; } } var static function curl_string ($url,$user_agent='Mozilla 4.0'){ $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_TIMEOUT, 120); $result = curl_exec ($ch); curl_close($ch); return $result; } } ?> with these changes I get a new error: Parse error: syntax error, unexpected T_STATIC, expecting T_VARIABLE in /home/admin/public_html/bb3portal/block/rss_feeds.php on line 106 Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245896 Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 try this... rss_feeds.php <?php // rss_feeds.php written by Static & Penagate @ http://staticfx.com // this file goes in the /bb3portal/block/ directory class OnlyHellRssFeed { var $nr_news=10; var $rss_channel = array(); var $currently_writing = ""; var $main = ""; var $item_counter = 0; var $template; var $feedname; var $url; function __construct($feedname, $url) { $this->feedname = $feedname; $this->url = $url; } function startElement($parser, $name, $attrs) { switch($name) { case "RSS": case "RDF:RDF": case "ITEMS": $this->currently_writing = ""; break; case "CHANNEL": $this->main = "CHANNEL"; break; case "IMAGE": $this->main = "IMAGE"; $this->rss_channel["IMAGE"] = array(); break; case "ITEM": $this->main = "ITEMS"; break; default: $this->currently_writing = $name; break; } } function endElement($parser, $name) { $this->currently_writing = ""; if ($name == "ITEM") { $this->item_counter++; } } function characterData($parser, $data) { if ($this->currently_writing != "") { switch($this->main) { case "ITEMS": if (isset($this->rss_channel[$this->main][$this->item_counter][$this->currently_writing])) { $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] .= $data; } else { //print ("rss_channel[$main][$item_counter][$currently_writing] = $data<br>"); $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] = $data; } break; } } } function get_data(&$template) { $xml_parser = xml_parser_create(); xml_set_element_handler( $xml_parser, array($this, 'startElement'), array($this, 'endElement') ); xml_set_character_data_handler( $xml_parser, array($this, 'characterData') ); $data = self::curl_string($this->url); xml_parse($xml_parser,$data); xml_parser_free($xml_parser); // putting in array $news=array(); if (isset($this->rss_channel["ITEMS"])) { if (count($this->rss_channel["ITEMS"]) > 0) for($i = 0;$i < count($this->rss_channel["ITEMS"]);$i++) $news[]=$this->rss_channel["ITEMS"][$i]; } $c=0; foreach($news as $key=>$val) { if($c<$this->nr_news) { $template->assign_block_vars($this->feedname, array( 'LINK' => $val['LINK'], 'TITLE' => $val['TITLE'], 'DESC' => $val['DESCRIPTION']) ); } $c++; } } function curl_string ($url,$user_agent='Mozilla 4.0'){ $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_TIMEOUT, 120); $result = curl_exec ($ch); curl_close($ch); return $result; } } ?> Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245900 Share on other sites More sharing options...
caspert_ghost Posted May 5, 2007 Author Share Posted May 5, 2007 with removing "static" and leaving function (getting closer) Fatal error: Undefined class name 'self' in /home/admin/public_html/bb3portal/block/rss_feeds.php on line 80 Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245903 Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 find that line and change self:: to $this-> and for any other you come across.... Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245907 Share on other sites More sharing options...
caspert_ghost Posted May 5, 2007 Author Share Posted May 5, 2007 great so far so good. I got no errors however the feeds are not showing up... the feeds are in another php file called feedlist.php after changing (there was only one) self:: to $this-> So I am wondering if I should combine the feeds and feedlist php's into 1 php file. Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245912 Share on other sites More sharing options...
caspert_ghost Posted May 5, 2007 Author Share Posted May 5, 2007 I decided this is just too much re coding so I will ask them again to update and if they refuse I will move to another host that offers up to date php and sql. Thank you all for your help in this matter. Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-245926 Share on other sites More sharing options...
caspert_ghost Posted May 8, 2007 Author Share Posted May 8, 2007 Well unfortunatly I must return to this issue as moving is now not an option for us at this time. A re glimps of what has aspired thus far. I have a script that is written in php 5 and I need some help in re writing it for php 4. The original code is: rss_feeds.php <?php class OnlyHellRssFeed { private $nr_news=10; private $rss_channel = array(); private $currently_writing = ""; private $main = ""; private $item_counter = 0; private $template; private $feedname; private $url; function __construct($feedname, $url) { $this->feedname = $feedname; $this->url = $url; } function startElement($parser, $name, $attrs) { switch($name) { case "RSS": case "RDF:RDF": case "ITEMS": $this->currently_writing = ""; break; case "CHANNEL": $this->main = "CHANNEL"; break; case "IMAGE": $this->main = "IMAGE"; $this->rss_channel["IMAGE"] = array(); break; case "ITEM": $this->main = "ITEMS"; break; default: $this->currently_writing = $name; break; } } function endElement($parser, $name) { $this->currently_writing = ""; if ($name == "ITEM") { $this->item_counter++; } } function characterData($parser, $data) { if ($this->currently_writing != "") { switch($this->main) { case "ITEMS": if (isset($this->rss_channel[$this->main][$this->item_counter][$this->currently_writing])) { $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] .= $data; } else { //print ("rss_channel[$main][$item_counter][$currently_writing] = $data<br>"); $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] = $data; } break; } } } function get_data(&$template) { $xml_parser = xml_parser_create(); xml_set_element_handler( $xml_parser, array($this, 'startElement'), array($this, 'endElement') ); xml_set_character_data_handler( $xml_parser, array($this, 'characterData') ); $data = self::curl_string($this->url); xml_parse($xml_parser,$data); xml_parser_free($xml_parser); // putting in array $news=array(); if (isset($this->rss_channel["ITEMS"])) { if (count($this->rss_channel["ITEMS"]) > 0) for($i = 0;$i < count($this->rss_channel["ITEMS"]);$i++) $news[]=$this->rss_channel["ITEMS"][$i]; } $c=0; foreach($news as $key=>$val) { if($c<$this->nr_news) { $template->assign_block_vars($this->feedname, array( 'LINK' => $val['LINK'], 'TITLE' => $val['TITLE'], 'DESC' => $val['DESCRIPTION']) ); } $c++; } } private static function curl_string ($url,$user_agent='Mozilla 4.0'){ $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_TIMEOUT, 120); $result = curl_exec ($ch); curl_close($ch); return $result; } } ?> This gave the error: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/admin/public_html/bb3portal/block/rss_feeds.php on line 9 When I change: private $nr_news=10; private $rss_channel = array(); private $currently_writing = ""; private $main = ""; private $item_counter = 0; private $template; private $feedname; private $url; private static function curl_string ($url,$user_agent='Mozilla 4.0'){ to: (removing the "private" code) var $nr_news=10; var $rss_channel = array(); var $currently_writing = ""; var $main = ""; var $item_counter = 0; var $template; var $feedname; var $url; var static function curl_string ($url,$user_agent='Mozilla 4.0'){ Parse error: syntax error, unexpected T_STATIC, expecting T_VARIABLE in /home/admin/public_html/bb3portal/block/rss_feeds.php on line 106 It was then said to remove "var static" and leave only function curl_string the new error: Fatal error: Undefined class name 'self' in /home/admin/public_html/bb3portal/block/rss_feeds.php on line 80 so I searched and found only 1 reference to self:: and changed it to $this-> now I get no errors but the list is not showing up as it should in my block. there are 2 more files that go with this: rss_feedlist.php <?php $feeds = array( 'mtgbks' => 'http://www.wizards.com/rss.asp?x=books', 'mtgdnd' => 'http://www.wizards.com/rss.asp?x=dnd', 'mtgd20' => 'http://www.wizards.com/rss.asp?x=d20modern', 'mtgebr' => 'http://www.wizards.com/rss.asp?x=eberron', 'mtgfr' => 'http://www.wizards.com/rss.asp?x=forgottenrealms', 'mtgmtg' => 'http://www.wizards.com/rss.asp?x=magic', 'mtgswrpg' => 'http://www.wizards.com/rss.asp?x=starwars-rpg', ); foreach ($feeds as $feed_name => $url) { $feed = new OnlyHellRssFeed($feed_name, $url); $feed->get_data($template); } ?> and rss_feeds.html which is the output page. if you could please look closley at this code and help with a rewrite for php 4 I would be gratly appreciative. Thank you Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-247968 Share on other sites More sharing options...
caspert_ghost Posted May 9, 2007 Author Share Posted May 9, 2007 anyone? Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-248629 Share on other sites More sharing options...
caspert_ghost Posted May 9, 2007 Author Share Posted May 9, 2007 This is driving me nutz.. why couldnt they make php 5 backward compatible. Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-248757 Share on other sites More sharing options...
caspert_ghost Posted May 10, 2007 Author Share Posted May 10, 2007 bump, still need assistance with this please. Link to comment https://forums.phpfreaks.com/topic/49949-php-version-help/#findComment-249818 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.