2

RSS ソースがあります。

http://feedity.com/rss.aspx/mr1-kossuth-hu/VVdXUlY
<item>
      <title>2008. november 23.</title>
      <link>http://www.mr1-kossuth.hu/m3u/0039c36f_3003051.m3u</link>
      <description>........</description>
      <pubDate>Wed, 26 Nov 2008 00:00:00 GMT</pubDate>
    </item>

これから、ポッドキャストに適したフィードを作成したいと思います。LINK の子を次のように置き換えたい:

http://stream001.radio.hu:8000/content/*.mp3

例:

<item>
      <title>2008. november 23.</title>
      <link>http://stream001.radio.hu:8000/content/0039c36f_3003051.mp3</link>
      <description>........</description>
      <pubDate>Wed, 26 Nov 2008 00:00:00 GMT</pubDate>
    </item>

PHPでそれを行うにはどうすればよいですか?

4

4 に答える 4

3

これはシンプルで純粋なXSLT1.0ソリューションであり、わずか47行で構成されており、その半分は終了タグです。次の変換

<xsl:stylesheet version = "1.0"
 xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">

 <xsl:outputomit-xml-declaration = "yes" />

 <xsl:param name = "pNewLink"
 select = "'http://stream001.radio.hu:8000/content/'" />

 <xsl:param name = "pNewExt" select="'。mp3'"/>

    <xsl:template match = "node()| @ *">
      <xsl:copy>
         <xsl:apply-templates select = "node()| @ *" />
      </ xsl:copy>
    </ xsl:template>

    <xsl:template match = "link">
      <xsl:copy>
         <xsl:copy-of select = "@ *" />

         <xsl:variable name = "vFName">
           <xsl:call-template name = "GetFileName">
             <xsl:with-param name = "pFPath"select="。"/>
           </ xsl:call-template>
         </ xsl:variable>

         <xsl:value-of select = "concat($ pNewLink、$ vFName、$ pNewExt)" />
      </ xsl:copy>
    </ xsl:template>

    <xsl:template name = "GetFileName">
      <xsl:param name = "pFPath" />

      <xsl:choose>
        <xsl:when test = "not(contains($ pFPath、'/'))">
          <xsl:value-of select = "substring-before($ pFPath、'。')" />
        </ xsl:when>

        <xsl:それ以外の場合>
          <xsl:call-template name = "GetFileName">
            <xsl:with-param name = "pFPath"
             select = "substring-after($ pFPath、'/')" />
          </ xsl:call-template>
        </ xsl:それ以外の場合>
      </ xsl:choose>
    </ xsl:template>
</ xsl:stylesheet>

提供されたソースXMLドキュメントに適用した場合

<アイテム>
    <タイトル>2008。11月23日。</title>
    <link> http://www.mr1-kossuth.hu/m3u/0039c36f_3003051.m3u </ link>
    <description> ........ </ description>
    <pubDate>2008年11月26日水曜日00:00:00GMT</ pubDate>
</ item>

必要な結果を生成します:

<アイテム>
    <タイトル>2008。11月23日。</title>
    <link> http://stream001.radio.hu:8000/content/0039c36f_3003051.mp3 </ link>
    <description> ........ </ description>
    <pubDate>2008年11月26日水曜日00:00:00GMT</ pubDate>
</ item>

このソリューションの次の特定の機能に注意してください。

  1. ID変換を使用およびオーバーライドするXSLTデザインパターンを使用します。

  2. 「GetFileName」という名前のテンプレートは、完全なURL(パラメーターとして渡される)から抽出され、ファイル拡張子が削除されたファイル名のみが抽出されます。これは、自分自身を再帰的に呼び出す名前付きテンプレートの良い例です

  3. 目的の新しいURLの構成要素は、グローバルとして指定されます<xsl:param>
于 2008-11-27T00:21:04.800 に答える
1

これは、 XSLTを使用して行うのが最適な種類のことです。簡単な XSL 変換を記述してそれを行うことも、ハックな方法で preg_match、preg_replace、およびその仲間を使用することもできます。

于 2008-11-26T19:22:34.557 に答える
0
<?php
 $str = file_get_contents('http://feedity.com/rss.aspx/mr1-kossuth-hu/VVdXUlY');
 $xml = simplexml_load_string($str);
if ($xml) {

$intro = str_replace('<link>http://www.mr1-kossuth.hu/m3u/', '<enclosure url="http://stream001.radio.hu:8000/content/', $xml->asXML());
$intro = str_replace('m3u</link>', 'mp3" type="audio/mpeg" />', $intro);
echo $intro;    
} else {
    $error = "Could not load intro XML file.";
}

?>
于 2008-11-26T20:59:51.150 に答える
0

最も簡単な方法は、単純な文字列置換です。

$str = file_get_contents('http://feedity.com/rss.aspx/mr1-kossuth-hu/VVdXUlY');
$str = str_replace('<link>http://www.mr1-kossuth.hu/m3u/', '<link>http://stream001.radio.hu:8000/content/', $str);
$str = str_replace('m3u</link>', 'mp3</link>', $str);

終わり!

于 2008-11-26T19:24:47.847 に答える