Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Include php
Forum PHP.pl > Forum > Przedszkole
nib
Witam. Mam problem otoz probuje includowac plik php ale mi sie nie udaje...
Wpisuje w kodzie takie cos:
  1. <?php 
  2.  
  3. include("rs.php"); ?>

i nie wyswietla mi zawartosci...

Zawartosc czytnika rss:
  1. <?php
  2. /*
  3.  +--------------------------------------------------+
  4.  | Author: Allan Irvine <ai@ayrsoft.com>  |
  5.  +--------------------------------------------------+
  6.  | Date: WED 03 MARCH 2004 |
  7.  +--------------------------------------------------+
  8.  | Origin: Scotland, United kingdom  |
  9.  +--------------------------------------------------+
  10.  | Script: newsReader.php  |
  11.  +--------------------------------------------------+
  12.  | No License  |
  13.  | free to use for personal and commercial purposes |
  14.  +--------------------------------------------------+
  15. */
  16.  
  17. //+++++++++++++++++++++++++++++++++++++++++++++++++++
  18. // CHANGES
  19. //---------------------------------------------------
  20. // Added a property $ampReplace, this is a quick fix
  21. // it is used to replace ampersands bfore php get a hold of
  22. // the rss file, and replace it once PHP has dealt with it
  23. // I was getting lines split by an ampersand, pointed out by
  24. // Mathew Clark of Divergent Systems, cheers.
  25. // I will need to address this later on as I deem this fix
  26. // as a bit of a kludge, not nice.
  27. // Allan Irvine <airvine@ayrsoft.com>
  28. // 29th April 2004
  29. //----------------------------------------------------
  30. //
  31. //++++++++++++++++++++++++++++++++++++++++++++++++++++
  32.  
  33.  
  34.  
  35. class newsReader{
  36.  
  37. var $content =  array();
  38. var $openTag =  array();
  39. var $closeTag =  array();
  40. var $currentTag;
  41. var $rss;
  42. var $level;
  43. var $startCollecting;
  44. var $wantedElements;
  45. var $cacheData;
  46. var $ampReplace;
  47.  
  48. function newsReader(){
  49. $this->rss = xml_parser_create();
  50. xml_set_object($this->rss, $this);
  51. xml_parser_set_option($this->rss,XML_OPTION_CASE_FOLDING,1);
  52. xml_set_element_handler($this->rss,_startElement,_endElement);
  53. xml_set_character_data_handler($this->rss,_parseData);
  54. $this->wantedElements['CHANNEL']  = array("TITLE","DESCRIPTION","LINK","IMAGES");
  55. $this->wantedElements['IMAGE']  = array("URL");
  56. $this->wantedElements['ITEM'] = array("TITLE","DESCRIPTION","LINK");
  57. }
  58.  
  59. function _findLevel($n){
  60. if(eregi("(CHANNEL)|(IMAGE)|(ITEM)",$n,$regs)){
  61. $this->level = $regs[0];
  62. }
  63. }
  64.  
  65. function _startToCollect($n){
  66. $this->startCollecting = (@in_array($n,$this->wantedElements[$this->level]))?1:0;
  67. }
  68.  
  69. function _startElement($t,$name,$attribs){
  70. $this->currentTag = $name;
  71. $this->_findLevel($name);
  72. $this->_startToCollect($name);
  73. if($this->startCollecting){
  74. $this->openTag[]="<tr><td>n";
  75. }
  76. }
  77.  
  78. function _endElement($t,$name){
  79. if($this->startCollecting)
  80. $this->closeTag[]="</td></tr>n";
  81. }
  82.  
  83. function _parseData($t,$cData){
  84. $cData = str_replace($this->ampReplace,"&",$cData);// quick fix, will need to address later on
  85. if(strlen(trim($cData))&&($this->startCollecting)){
  86. if(eregi("link",$this->currentTag)){
  87. $this->content[]="<A HREF="".$cData."" TARGET="_BLANK">".$cData."</A>n";
  88. }elseif(eregi("url",$this->currentTag)){
  89. $this->content[]="<IMG SRC="".$cData."">n";
  90. }else{
  91. $this->content[]=$cData;
  92. }
  93. }
  94. }
  95.  
  96. function readNewsFeed($source){
  97.  
  98. $this->_readCacheData();
  99. if($this->_useCache($source)){
  100. $this->_writeCacheEntry($source);
  101. $file = file("newsCache/".md5($source));
  102. }else{
  103. $file = file($source);
  104. }
  105. $file = implode("n",$file);
  106. $this->ampReplace = md5(time());// quick fix, will need to address later on
  107. $file = str_replace("&",$this->ampReplace,$file);// quick fix, will need to address later on
  108.  
  109. if(!xml_parse($this->rss,$file,1)){
  110. $ln = xml_get_current_line_number($this->rss);
  111. $msg = xml_error_string(xml_get_error_code($this->rss));
  112. return ("An XML error occurred on line $ln: $msg");
  113. }else{
  114. $rtn = "<TABLE border=0>n";
  115. for($i=0;$i<count($this->openTag);$i++){
  116. $rtn.= $this->openTag[$i].$this->content[$i].$this->closeTag[$i];
  117. }
  118. $rtn.="</TABLE>n";
  119.  
  120. if(!$this->_useCache($source)){
  121. $this->_writeCacheEntry($source);
  122. }
  123.  
  124. return $rtn;
  125.  
  126. }
  127. }
  128.  
  129.  
  130. function _checkCacheDir(){
  131. if(!is_dir("newsCache")){
  132. mkdir("newsCache");
  133. }
  134. }
  135.  
  136. function _readCacheData(){
  137. $file = file("newsCache/newsReaderCache.php");
  138. if(strlen(trim($file[0]))){
  139. $this->cacheData = unserialize($file[0]);
  140. }
  141. }
  142.  
  143. function _useCache($source){
  144. if($key = array_search($source,$this->cacheData)){
  145. $sec = explode(" ",$key);
  146. if((time() - $sec[1])>(3600)){
  147. return 0;
  148. }else{
  149. return 1;
  150. }
  151. }else{
  152. return 0;
  153. }
  154. }
  155.  
  156. function _writeCacheEntry($source){
  157. $this->_checkCacheDir();
  158. $this->_updateCacheArray($source);
  159. $fp = fopen("newsCache/newsReaderCache.php","w");
  160. fwrite($fp,serialize($this->cacheData));
  161. fclose($fp);
  162.  
  163. $data = file($source);
  164. $data = implode("n",$data);
  165. $fp = fopen("newsCache/".md5($source),"w");
  166. fwrite($fp,$data);
  167. fclose($fp);
  168.  
  169. }
  170.  
  171. function _updateCacheArray($source){
  172.  
  173. if(is_array($this->cacheData) && in_array($source,$this->cacheData)){
  174. foreach($this->cacheData as $key=>$val){
  175. if(trim($val) == trim($source)){
  176. $key =microtime();
  177. }
  178. $new[$key]= $val;
  179. }
  180. $this->cacheData = $new;
  181. }else{
  182. $this->cacheData[microtime()] = $source;
  183. }
  184. }
  185.  
  186. }
  187.  
  188. //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  189. //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  190. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  191. //
  192. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  193. // test data below once you are happy how it works just remove this stuff
  194. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  195.  
  196. // bbc news stories
  197.  
  198. $newsSources['Dzielnica Smolna']['Smolna']="http://smolna.rybnik.pl/smolna_rss.xml";
  199.  
  200.  
  201.  
  202.  
  203.  
  204. ?>
  205. <style type=text/css><!--
  206. td {
  207. font-family:arial,verdana,tahoma;
  208. font-size:12px;
  209. background-color:#f0f0f0;
  210. color:#000000;
  211. }
  212. --></style>
  213. <?php
  214.  
  215.  
  216. foreach($newsSources as $name=>$array)
  217.  
  218. //++++++++++++++++
  219. // script usage |
  220. //++++++++++++++++
  221. #$source = "http://www.newscientist.com/syndication/news.rdf";
  222. #$go = 1;
  223. if($go){
  224. $feed = new newsReader;
  225. echo $feed->readNewsFeed($source);
  226. }
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236. ?>
php programmer
Zamień include na require to wyświetli ci jaki jest błąd
revyag
Zamykam.

Proszę zapoznać się z:

Temat: Tematyka i zasady panujace na forum Przedszkole

i przesłać mi na pw co zrobiłeś źle i jak chcesz to poprawić. Wtedy odblokuję.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.