2012-09-06 55 views
-1

我對PhP和JS非常陌生。 我有一個網站可以跟蹤多個RSS源。我通過使用第三方網站來完成這項工作,該網站可以讓我將RSS轉換爲具有CSS樣式的JavaScript功能。如果JS結果中符合某些關鍵字,需要隱藏將RSS源轉換爲JS

我注意到有時RSS源會在主機端因任何原因離線,但我希望能夠使用PhP或其他方法來識別JS結果中的某些關鍵字,並且不顯示該源。 我在頁面中沒有PhP,只有HTML,CSS和Javascript。下面是我正在使用的JS Feed中的一個。

src="http://feed2js.org//feed2js.php? src=http%3A%2F%2Fajaxplorer.info%2Ffeed&chan=title&num=10&date=y&utf=y" charset="UTF-8" type="text/javascript"></script>

<noscript><a href="http://feed2js.org//feed2js.php?src=http%3A%2F%2Fajaxplorer.info%2Ffeed&chan=title&num=10&date=y&utf=y&html=y">View RSS feed</a>

回答

0

如果妳使用JQuery,我ü可以使用這個代碼:

<!doctype html> 
<html> 
<head> 
    <title>Property Agents</title> 

</head> 
<body> 
    <!-- including JQuery from google CDN --> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> 

    <div class="content"> 
     <div class="rss"> 
      <!-- here is your script, which will paste here news--> 
      <script src="http://feed2js.org//feed2js.php?src=http%3A%2F%2Fajaxplorer.info%2Ffeed&chan=title&num=10&date=y&utf=y&html=y"></script> 
     </div> 
    </div> 

    <script> 
     $(document).ready(function(){ 
      var text,pos; 
      $('.rss-item').each(function(){ 
       // getting html of each element 
       text = $(this).html(); 
       // search text in item 
       pos = text.indexOf('AjaXplorer 4.2'); 
       // found? then hide it 
       if (pos != -1) $(this).hide(); 
      }); 
     }); 
    </script> 
</body> 
</html> 

這個代碼是找到與 'AjaXplorer 4.2' 文本中的所有新聞和隱藏它。
全部工作示例(只是爲了確保它的工作)U可以看到在
http://pastehtml.com/view/car52rb92.html

Declaimer
這不是一個很好的解決方案。使用PHP更好地生成頁面,並在服務器端篩選這些消息。這很容易,夥計。可能是10-20行代碼。
想法很簡單的PHP解決方案:從URL
1.獲取數據與file_get_contents
2.然後通過線路和查找u需要(用SimpleXML解析更好)在HTML頁面
3.輸出修改後的數據與一條代碼行如<?php echo %text ?>

相關問題