[Variablen] Array fehler

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [Variablen] Array fehler

    Hallo

    Ich möchte aus einem RDF (RSS) File, einen Java Ticker erstellen.

    Hier mein bisheriger Quellcode:

    PHP-Code:
    <?
    $host = 'media-designs.de';
    $uri = 'winfuture.rdf';
    $fp = fsockopen($host, 80, $errno, $errstr, 20);
    if (!$fp) {
    die("Network error: $errstr ($errno)");
    } else {
    $xml = '';
    fputs($fp, "GET /$uri HTTP/1.0\r\nHost: $host\r\n\r\n");
    while (!feof($fp)) {
    $xml .= fgets($fp, 128);
    }
    fclose ($fp);
    }

    function untag($string, $tag) {
    $tmpval = array();
    $preg = "|<$tag>(.*?)</$tag>|s";
    preg_match_all($preg, $string, $tags);
    foreach ($tags[1] as $tmpcont){
    $tmpval[] = $tmpcont;
    }
    return $tmpval;
    }

    $items = untag($xml, 'item');
    $html = '<p>';
    foreach ($items as $item) {
    $title = untag($item, 'title');
    $link = untag($item, 'link');
    }
    ?>
    <html>
    <body>
    <applet code="NavigatorTicker.class" align="baseline" width="400" height="28">
          <param name="bgco" value="0,0,170">
          <param name="count" value="4">
          <param name="msg0"
    value=" <? echo $title[0] ?> \\ <? echo $link[0] ?> \n">
          <param name="msg1"
    value=" <? echo $title[1] ?> \\ <? echo $link[1] ?> ">
          <param name="msg2"
    value="<? echo $title[2] ?> \\ <? echo $link[2] ?> ">
          <param name="msg3"
    value="<? echo $title[3] ?> \\ <? echo $link[3] ?> ">
          <param name="speed" value="5">
          <param name="txtco" value="200,200,255">
        </applet>
        
        </html>
        </body>
    In Action und das class file siehe hier

    Der erste eintrag wird richtig übersetzt. aber bei den restlichen erhalte ich immer:

    Undefined offset: 1 in ...

    Warum? Wo ist da bitte der Fehler, warum funkt der erste parameter und die anderen nicht?
    Kann mir bitte jemand helfen. Danke!

    PHP-Code:
    $html .= '<a href="' $link[0] . '">' $title[0] . "</a><br />\n";
    }
    $html .= '</p>';
    echo 
    $html
    Das war der originale Code vom Newsgrabber.

  • #2
    Re: [Variablen] Array fehler

    Original geschrieben von christian12345
    Undefined offset: 1 in ...
    d.h. das der offset (der key) im array nicht definiert ist.

    prüfen kannst du das mit isset().

    PHP-Code:
    if (isset($arrayvar[1])) echo $arrayvar[1]; 
    INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


    Kommentar


    • #3
      da ist der fehler:
      PHP-Code:
      foreach ($tags[1] as $tmpcont){ 
      ich glaub, so wäre es besser:
      PHP-Code:
      foreach ($tags as $tmpcont){ 
      hopka.net!

      Kommentar


      • #4
        ich glaub, so wäre es besser:
        PHP-Code:
        foreach ($tags as $tmpcont){ 
        Danke erstmal. Jedoch wenn ich das ändere, erhalte ich 4 Mal die Fehlermeldung:

        Array to string conversion bei der Funktion preg_match_all

        Wenn es mit
        PHP-Code:
         $html .= '<a href="' $link[0] . '">' $title[0] . "</a><br />\n";
        }
        $html .= '</p>';
        echo 
        $html
        aufgerufen wird, funkioniert es ja. Das ist ja das komische.
        Zuletzt geändert von christian12345; 15.06.2003, 17:44.

        Kommentar


        • #5
          hallo

          Kann mir bitte jemand helfen? Bitte, da drinnen ist ja nur ein kleines Problem.

          Kommentar


          • #6
            hast du eigentlich die lösung von mir mal ausprobiert?
            INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


            Kommentar


            • #7
              Ja habe ich. Funktioniert leider auch nicht.

              Kommentar


              • #8
                PHP-Code:
                // mache mal aus
                $preg "|<$tag>(.*?)</$tag>|s";

                // das hier
                $preg "|<".$tag.">(.*?)</".$tag.">|s"
                geht es jetzt?

                ich muss leider raten.

                in welcher zeile tritt denn der fehler eigentlich auf?
                INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                Kommentar


                • #9
                  Hallo

                  Leider hat sich überhaupt nix verändert. Ich erhalte immer noch die Gleiche Fehlermeldung. Aber die Erste News wird angezeigt.

                  PHP-Code:
                  Undefined offset:  1 in <b></bon line <b>79</b><br /> 
                  Das ist folgende Zeile:

                  PHP-Code:
                  value=" <? echo $title[1] ?> \ <? echo $link[1] ?> ">
                  wo hier der Fehler ist, würde ich auch gerne wissen. Aber danke dass du mir helfen möchtest!

                  Kommentar


                  • #10
                    ok. dann der nächste schritt.

                    mache vor jedes < ein \
                    ausserdem verändern wir ein wenig den filter.

                    PHP-Code:
                    $preg "|\\<".$tag.">(.*?)\\</".$tag.">|isU"
                    INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                    Kommentar


                    • #11
                      Danke nochmals

                      Seit der Letzen Änderung schaut die Ausgabe am Applet schon besser aus:

                      News 1 [/title1] [/link] News 2 [/link] [/item] [item] [title] NEws 2...

                      usw. natürlich spitze klammern.

                      Ich werde mich noch rumspielen, vielleicht schaffe ich es noch.

                      Kommentar


                      • #12
                        Mensch, das ist kompliziert. Jetzt wird wieder alles den ersten Parameter den Java applet übergeben. Normalerweise müsste ja nur text \\ link stehen.


                        Hier mal die Ausgabe:

                        PHP-Code:
                        <applet code="NavigatorTicker.class" align="baseline" width="400" height="28">

                              <
                        param name="bgco" value="0,0,170">

                              <
                        param name="count" value="4">

                              <
                        param name="msg0"

                        value=" \MSN Messenger 6 Public Preview - Download Inside</title>
                        <link>[url]http://www.WinFuture.de/news.php?show=9335[/url]</link>
                        </item>

                        <item>
                        <title>Hardware: Iomega DVD-Brenner, nForce2-Test, WD S-ATA und AOpen</title>
                        <link>[url]http://www.WinFuture.de/news.php?show=9334[/url]</link>
                        </item>

                        usw......

                              <param name="
                        msg1"

                        value=" 
                        \<br />
                        <
                        b>Notice</b>:  Undefined offset:  1 in <b>c:\wampp13cs\htdocs\test\2222.php</bon line <b>79</b><br />
                         \ <
                        br />
                        <
                        b>Notice</b>:  Undefined offset:  1 in <b>c:\wampp13cs\htdocs\test\2222.php</bon line <b>79</b><br />
                         
                        ">

                              <param name="
                        msg2"

                        value="
                        <br />
                        <
                        b>Notice</b>:  Undefined offset:  2 in <b>c:\wampp13cs\htdocs\test\2222.php</bon line <b>83</b><br />
                         \\ <
                        br />
                        <
                        b>Notice</b>:  Undefined offset:  2 in <b>c:\wampp13cs\htdocs\test\2222.php</bon line <b>83</b><br />
                         
                        "> 

                        Kommentar


                        • #13
                          mhm. da muss wohl jemand ran, der die regex besser beherrscht als ich...
                          INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                          Kommentar

                          Lädt...
                          X