PHPでRSSサブスクリプションを生成する方法、phprssサブスクリプション
この記事の例では、php で RSS サブスクリプションを生成する方法を説明します。参考のためにみんなで共有してください。具体的な分析は次のとおりです:
RSS (Really Simple Syndication、シンジケート コンテンツとも呼ばれる) は、Web サイトのコンテンツを記述および同期するための形式です。 RSS は、次の 3 つの解釈のいずれかになります: Really Simple Syndication、RDF (リソース記述フレームワーク) サイトの概要。しかし実際には、これら 3 つの説明はすべて同じシンジケーション テクノロジーについて言及しています。 RSS は現在、オンライン ニュース チャネル、ブログ、Wiki で広く使用されています。 RSS 購読を使用すると、Web サイトで情報をより迅速に取得できるため、ユーザーは Web サイトのコンテンツの最新の更新を取得するのに役立ちます。ネットワーク利用者は、クライアント上でRSSに対応したアグリゲーションツールソフトを利用することで、Webサイトのコンテンツページを開かずにRSS出力に対応したWebサイトのコンテンツを閲覧できます。
技術的に言えば、RSS ファイルは標準化された XML データであり、通常、ファイルには rss、xml、または rdf が接尾辞として付けられます。以下は、rss ファイルの内容の例です。
以下は、php を使用して RSS を動的に生成するコード例です。
コードをコピーします
コードは次のとおりです:
** PHP は RSS クラスを動的に生成します
**/
定義("タイムゾーン","");
define("FEEDCREATOR_VERSION","www.jb51.net");//您的网址
class FeedItem extends HtmlDescribable{
var $title,$description,$link;
var $author,$authorEmail,$image,$category,$comments,$guid,$source,$creator;
var $date;
var $AdditionalElements=Array();
}
class FeedImage extends HtmlDescribable{
var $title,$url,$link;
var $width,$height,$description;
}
class HtmlDescribable{
var $descriptionHtmlSyndicated;
var $descriptionTruncSize;
関数 getDescription(){
$descriptionField=new FeedHtmlField($this->description);
$descriptionField->syndicateHtml=$this->descriptionHtmlSyndicated;
$descriptionField->truncSize=$this->descriptionTruncSize;
return $descriptionField->output();
}
}
クラス FeedHtmlField{
var $rawFieldContent;
var $truncSize,$syndicateHtml;
関数 FeedHtmlField($parFieldContent){
if($parFieldContent){
$this->rawFieldContent=$parFieldContent;
}
}
関数出力(){
if(!$this->rawFieldContent){
$結果="";
} elseif($this->syndicateHtml){
$result="rawFieldContent."]]>";
}その他{
if($this->truncSize と is_int($this->truncSize)){
$result=FeedCreator::iTrunc(htmlspecialchars($this->rawFieldContent),$this->truncSize);
}その他{
$result=htmlspecialchars($this->rawFieldContent);
}
}
$result を返します。
}
}
class UniversalFeedCreator extends FeedCreator{
var $_feed;
関数 _setFormat($format){
スイッチ (strtoupper($format)){
ケース「2.0」:
// 失敗します
ケース「RSS2.0」:
$this->_feed=new RSSCreator20();
壊す;
ケース「0.91」:
// 失敗します
ケース「RSS0.91」:
$this->_feed=new RSSCreator091();
壊す;
デフォルト:
$this->_feed=new RSSCreator091();
壊す;
}
$vars=get_object_vars($this);
foreach ($vars as $key => $value){
// プロパティ "contentType","encoding" の上書きを防止します。 「_feed」自体をコピーしないでください
if(!in_array($key, array("_feed","contentType","encoding"))){
$this->_feed->{$key}=$this->{$key};
}
}
}
関数 createFeed($format="RSS0.91"){
$this->_setFormat($format);
return $this->_feed->createFeed();
}
function saveFeed($format="RSS0.91",$filename="",$displayContents=true){
$this->_setFormat($format);
$this->_feed->saveFeed($filename,$displayContents);
}
関数 useCached($format="RSS0.91",$filename="",$timeout=3600){
$this->_setFormat($format);
$this->_feed->useCached($filename,$timeout);
}
}
class FeedCreator extends HtmlDescribable{
var $title,$description,$link;
var $syndicationURL,$image,$ language,$copyright,$pubDate,$lastBuildDate,$editor,$editorEmail,$webmaster,$category,$docs,$ttl,$評価,$skipHours,$skipDays;
var $xslStyleSheet="";
var $items=Array();
var $contentType="アプリケーション/xml";
var $encoding="utf-8";
var $AdditionalElements=Array();
関数 addItem($item){
$this->items[]=$item;
}
関数clearItem2Null(){
$this->items=array();
}
関数 iTrunc($string,$length){
if(strlen($string) $string を返します。
}
$pos=strrpos($string,".");
if($pos>=$length-4){
$string=substr($string,0,$length-4);
$pos=strrpos($string,".");
}
if($pos>=$length*0.4){
return substr($string,0,$pos+1)." ...";
}
$pos=strrpos($string," ");
if($pos>=$length-4){
$string=substr($string,0,$length-4);
$pos=strrpos($string," ");
}
if($pos>=$length*0.4){
return substr($string,0,$pos)." ...";
}
substr($string,0,$length-4) を返します。" ...";
}
関数 _createGeneratorComment(){
return "n";
}
function _createAdditionalElements($elements,$indentString=""){
$ae="";
if(is_array($elements)){
foreach($elements AS $key => $value){
$ae.= $indentString."$value$key>n";
}
}
$aeを返します;
}
関数 _createStylesheetReferences(){
$xml="";
if($this->cssStyleSheet) $xml .= "cssStyleSheet."" type="text/css"?>n";
if($this->xslStyleSheet) $xml .= "xslStyleSheet."" type="text/xsl"?>n";
$xml を返します。
}
関数 createFeed(){}
関数 _generateFilename(){
$fileInfo=pathinfo($_SERVER["PHP_SELF"]);
return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".xml";
}
関数 _redirect($filename){
Header("Content-Type: ".$this->contentType."; charset=".$this->encoding."; filename=".basename($filename));
Header("Content-Disposition: inline; filename=".basename($filename));
readfile($filename,"r");
死ぬ();
}
関数 useCached($filename="",$timeout=3600){
$this->_timeout=$timeout;
if($filename==""){
$filename=$this->_generateFilename();
}
if(file_exists($filename) && (time()-filemtime($filename) $this->_redirect($filename);
}
}
関数 saveFeed($filename="",$displayContents=true){
if($filename==""){
$filename=$this->generateFilename();
}
$feedFile=fopen($filename,"w+");
if($feedFile){
fputs($feedFile,$this->createFeed());
fclose($feedFile);
if($displayContents){
$this->_redirect($filename);
}
}その他{
echo "
フィード ファイルの作成中にエラーが発生しました。書き込み権限を確認してください。
";
}
}
}
クラス FeedDate{
var $unix;
関数 FeedDate($dateString=""){
if($dateString=="") $dateString=date("r");
if(is_integer($dateString)){
$this->unix=$dateString;
戻る;
}
if(preg_match("~(?:(?:月|火|水|木|金|土|日),\s+)?(\d{1,2})\s+([a-zA-Z] {3})\s+(\d{4})\s+(\d{2}):(\d{2}):(\d{2})\s+(.*)~",$dateString, $matches)){
$months=Array("1月"=>1,"2月"=>2,"3月"=>3,"4月"=>4,"5月"=>5,"6月"=> ;6、「7月」=>7、「8月」=>8、「9月」=>9、「10月」=>10、「11月」=>11、「12月」=>12 );
$this->unix=mktime($matches[4],$matches[5],$matches[6],$months[$matches[2]],$matches[1],$matches[3]);
if(substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-'){
$tzOffset=(substr($matches[7],0,3) * 60 + substr($matches[7],-2)) * 60;
}その他{
if(strlen($matches[7])==1){
$1時間=3600;
$ord=ord($matches[7]);
if($ord $tzOffset=(ord("A") - $ord - 1) * $oneHour;
} elseif($ord >= ord("M") && $matches[7]!="Z"){
$tzOffset=($ord - ord("M")) * $oneHour;
elseif($matches[7]=="Z"){
$tzOffset=0;
}
}
スイッチ ($matches[7]){
ケース「UT」:
ケース「GMT」: $tzOffset=0;
}
}
$this->unix += $tzOffset;
戻る;
}
if(preg_match("~(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{ 2})(.*)~",$dateString,$matches)){
$this->unix=mktime($matches[4],$matches[5],$matches[6],$matches[2],$matches[3],$matches[1]);
if(substr($matches[7],0,1)=='+' OR substr($matches[7],0,1)=='-'){
$tzOffset=(substr($matches[7],0,3) * 60 + substr($matches[7],-2)) * 60;
}その他{
if($matches[7]=="Z"){
$tzOffset=0;
}
}
$this->unix += $tzOffset;
戻る;
}
$this->unix=0;
}
関数 rfc822(){
$date=gmdate("Y-m-d H:i:s",$this->unix);
if(TIME_ZONE!="") $date .= " ".str_replace(":","",TIME_ZONE);
$date を返します。
}
関数 iso8601(){
$date=gmdate("Y-m-d H:i:s",$this->unix);
$date=substr($date,0,22) 。 ':' 。 substr($date,-2);
if(TIME_ZONE!="") $date=str_replace("+00:00",TIME_ZONE,$date);
$date を返します。
}
関数 unix(){
$this->unix を返す;
}
}
クラス RSSCreator10 は FeedCreator を拡張します{
関数 createFeed(){
$feed="encoding.""?>n";
$feed.= $this->_createGeneratorComment();
if($this->cssStyleSheet==""){
$cssStyleSheet="http://www.w3.org/2000/08/w3c-synd/style.css";
}
$feed.= $this->_createStylesheetReferences();
$feed.= "
$feed.= " xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"n";
$feed.= " xmlns:slash="http://purl.org/rss/1.0/modules/slash/"n";
$feed.= " xmlns:dc="http://purl.org/dc/elements/1.1/">n";
$feed.= "
$feed.= "
$feed.= "
$feed.= " ".$this->link."n";
if($this->image!=null){
$feed.= "
}
$now=新しいフィード日付();
$feed.= "
$feed.= " n";
$feed.= "
for ($i=0;$i
$feed.= "
}
$feed.= "
$feed.= " n";
$feed.= "
if($this->image!=null){
$feed.= "
$feed.= "
$feed.= " ".$this->image->link."n";
$feed.= "
$feed.= "
}
$feed.= $this->_createAdditionalElements($this->AdditionalElements," ");
for ($i=0;$i
$feed.= "
//$feed.= "
$feed.= "
if($this->items[$i]->date!=null){
$itemDate=new FeedDate($this->items[$i]->date);
$feed.= "
}
if($this->items[$i]->source!=""){
$feed.= "
}
if($this->items[$i]->author!=""){
$feed.= "
}
$feed.= "
$feed.= " ".htmlspecialchars($this->items[$i]->link)."n";
$feed.= "
$feed.= $this->_createAdditionalElements($this->items[$i]->AdditionalElements," ");
$feed.= "
}
$feed.= "n";
$feed を返します。
}
}
クラス RSSCreator091 は FeedCreator を拡張します{
var $RSSVersion;
関数 RSSCreator091(){
$this->_setRSSVersion("0.91");
$this->contentType="アプリケーション/rss+xml";
}
function _setRSSVersion($version){
$this->RSSVersion=$version;
}
関数 createFeed(){
$feed="encoding.""?>n";
$feed.= $this->_createGeneratorComment();
$feed.= $this->_createStylesheetReferences();
$feed.= "
$feed.= " n";
$feed.= "
$this->descriptionTruncSize=500;
$feed.= "
$feed.= " ".$this->link."n";
$now=新しいフィード日付();
$feed.= "
$feed.= "
if($this->image!=null){
$feed.= " n";
$feed.= "
$feed.= "
$feed.= " ".$this->image->link."n";
if($this->image->width!=""){
$feed.= "
}
if($this->image->height!=""){
$feed.= " ".$this->image->height."高さ>n";
}
if($this->image->description!=""){
$feed.= "
}
$feed.= " n";
}
if($this->言語!=""){
$feed.= " ".$this->言語."言語>n";
}
if($this->copyright!=""){
$feed.= "
}
if($this->エディタ!=""){
$feed.= "
}
if($this->ウェブマスター!=""){
$feed.= "
}
if($this->pubDate!=""){
$pubDate=new FeedDate($this->pubDate);
$feed.= "
}
if($this->category!=""){
$feed.= "
}
if($this->docs!=""){
$feed.= "
}
if($this->ttl!=""){
$feed.= "
}
if($this->評価!=""){
$feed.= " ".FeedCreator::iTrunc(htmlspecialchars($this->評価),500)."評価>n";
}
if($this->skipHours!=""){
$feed.= "
}
if($this->skipDays!=""){
$feed.= "
}
$feed.= $this->_createAdditionalElements($this->AdditionalElements," ");
for ($i=0;$i
$feed.= " n";
$feed.= "
$feed.= " ".htmlspecialchars($this->items[$i]->link)."n";
$feed.= "
if($this->items[$i]->author!=""){
$feed.= "
}
/*
// 保留中
if($this->items[$i]->source!=""){
$feed.= "
}
*/
if($this->アイテム[$i]->カテゴリ!=""){
$feed.= "
}
if($this->アイテム[$i]->コメント!=""){
$feed.= "
}
if($this->items[$i]->date!=""){
$itemDate=new FeedDate($this->items[$i]->date);
$feed.= "
}
if($this->items[$i]->guid!=""){
$feed.= "
}
$feed.= $this->_createAdditionalElements($this->items[$i]->AdditionalElements," ");
$feed.= " n";
}
$feed.= " n";
$feed.= "
$feed を返します。
}
}
クラス RSSCreator20 は RSSCreator091 を拡張します{
関数 RSSCreator20(){
親::_setRSSVersion("2.0");
}
}
使用例:
$item=新しいフィードアイテム(); $item->title =$rowbrs['件名']; $item->link='http://www.bkjia.com/'; $item->説明 =$rowbrs['説明']
$rss->addItem($item); }
mysql_close($db); $rss->saveFeed("RSS2.0","rss.xml");
この記事で説明した内容が皆様の PHP プログラミング設計に役立つことを願っています。
http://www.bkjia.com/PHPjc/958257.html
www.bkjia.com
true
http://www.bkjia.com/PHPjc/958257.html

負荷分散はセッション管理に影響しますが、セッションの複製、セッションの粘着性、集中セッションストレージで解決できます。 1。セッションレプリケーションサーバー間のセッションデータをコピーします。 2。セッションスティンネスは、ユーザーリクエストを同じサーバーに指示します。 3.集中セッションストレージは、Redisなどの独立したサーバーを使用してセッションデータを保存してデータ共有を確保します。

SESSIONLOCKINGISATECHNIQUESTOESUREAUSER'SSESSIONREMAINSEXCLUSIVETOONEUSATIME.ITISCRUCIALFORPREVENTINGDATACORTIONANDSECURITYBREACHESINMULTI-USERAPPLICATIONS.SESSIONLOCKINGISISIMPLEMENTEDUSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGSINGROCKINGSMECHANISMなど

PHPセッションの代替品には、Cookie、トークンベースの認証、データベースベースのセッション、Redis/Memcachedが含まれます。 1.Cookiesは、クライアントにデータを保存することによりセッションを管理します。 2.トークンベースの認証はトークンを使用してユーザーを検証します。これは非常に安全ですが、追加のロジックが必要です。 3.Databaseベースのセッションは、データベースにデータを保存します。これは、スケーラビリティが良好ですが、パフォーマンスに影響を与える可能性があります。 4. Redis/Memcachedは分散キャッシュを使用してパフォーマンスとスケーラビリティを向上させますが、追加のマッチングが必要です

SessionHijackingとは、ユーザーのSessionIDを取得してユーザーになりすましている攻撃者を指します。予防方法には、次のものが含まれます。1)HTTPSを使用した通信の暗号化。 2)SessionIDのソースの検証。 3)安全なSessionID生成アルゴリズムの使用。 4)SessionIDを定期的に更新します。

この記事では、PHPについて説明し、その完全なフォーム、Web開発での主要な使用、PythonとJavaとの比較、および初心者の学習のしやすさについて説明します。

PHPは、$ \ _ postおよび$ \ _を使用してフォームデータを処理し、検証、消毒、安全なデータベースインタラクションを通じてセキュリティを確保します。

この記事では、PHPとASP.NETを比較して、大規模なWebアプリケーション、パフォーマンスの違い、セキュリティ機能への適合性に焦点を当てています。どちらも大規模なプロジェクトでは実行可能ですが、PHPはオープンソースであり、プラットフォームに依存しませんが、ASP.NET、

PHPの症例感度は変化します:関数は鈍感であり、変数とクラスは感度があります。ベストプラクティスには、一貫した命名と、比較のためにケース非感受性関数を使用することが含まれます。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

SublimeText3 中国語版
中国語版、とても使いやすい

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

ホットトピック









