Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> SimpleXML - wyciaganie obrazka z xml
zukowskp
post 17.07.2008, 17:52:46
Post #1





Grupa: Zarejestrowani
Postów: 23
Pomógł: 3
Dołączył: 8.07.2008

Ostrzeżenie: (0%)
-----


Witam, mam taki plik xml
Kod
<?xml version="1.0" encoding="iso-8859-2"?>
   <offers>
       <offer>
         <id>1145</id>
         <name>Ice Dive Adidas Woda toaletowa 100 ml</name>
         <price>45.00</price>
         <url>http://www.kokai.pl/item1145_Woda_toaletowa_Ice_Dive_Adidas</url>
         <categoryId>Meskie/Woda toaletowa</categoryId>
         <description></description>
         <image>http://www.kokai.pl/obrazki/duze/3285434.jpg</image>
         <attributes>
           <attribute>
             <name>Producent</name>
             <value>Adidas</value>
           </attribute>
           <attribute>
             <name>Model</name>
             <value>Ice Dive</value>
           </attribute>
           <attribute>
             <name>Rodzaj</name>
             <value>Woda toaletowa</value>
           </attribute>
           <attribute>
             <name>Pojemnosc</name>
             <value>100 ml</value>
           </attribute>
         </attributes>
       </offer>
       <offer>
         <id>1147</id>
         <name>Sport Field Adidas Woda toaletowa 100 ml</name>
         <price>45.00</price>
         <url>http://www.kokai.pl/item1147_Woda_toaletowa_Sport_Field_Adidas</url>
         <categoryId>Meskie/Woda toaletowa</categoryId>
         <description></description>
         <image>http://www.kokai.pl/obrazki/duze/2374250.jpg</image>
         <attributes>
           <attribute>
             <name>Producent</name>
             <value>Adidas</value>
           </attribute>
           <attribute>
             <name>Model</name>
             <value>Sport Field</value>
           </attribute>
           <attribute>
             <name>Rodzaj</name>
             <value>Woda toaletowa</value>
           </attribute>
           <attribute>
             <name>Pojemnosc</name>
             <value>100 ml</value>
           </attribute>
         </attributes>
       </offer>
       </offers>


napisalem do tego taki skrypcik
Kod
<?php
      echo 'Produkty: <br/>';
    
      $offers = simplexml_load_file('maly.xml');
    
      foreach($offers -> offer as $offer){
         echo 'Id: '.$offer -> id.'; Name: '.$offer -> name.'; Price: '.$offer -> price.';
          Url: '.$offer -> url.'; categoryId: '.$offer -> categoryId.'; Image: '.$offer -> image.';
          Producent: '.$offer -> producent.'<br/>';
         echo 'Szczegóły: <br/>';
         foreach($offer -> attributes -> attribute as $attribute){
            echo 'Name: '.$attribute -> name.'; Value: '.$attribute -> value.'<br/>';
         }
         echo '<hr/>';
      }
   ?>


Czy ktos moze mi podpowiedziec co robie zle?

na stronie zwraca mi tez taki blad: Warning: Invalid argument supplied for foreach()

a skrypt pisalem na podstawie podobnego przykladu z netu.

ok juz naprawilem! smile.gif

czy wie ktos moze jak zrobic zeby link do obrazka byl pobierany jako obrazek a nie zwykly link do obrazka?

Ten post edytował zukowskp 17.07.2008, 20:06:27
Go to the top of the page
+Quote Post
quality
post 17.07.2008, 20:38:07
Post #2





Grupa: Zarejestrowani
Postów: 172
Pomógł: 9
Dołączył: 13.02.2006
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Proste
nie robisz <a href="http://www.kokai.pl/obrazki/duze/2374250.jpg"> cos</a>
tylko
<img src="http://www.kokai.pl/obrazki/duze/2374250.jpg />


--------------------
Go to the top of the page
+Quote Post
zukowskp
post 18.07.2008, 09:29:54
Post #3





Grupa: Zarejestrowani
Postów: 23
Pomógł: 3
Dołączył: 8.07.2008

Ostrzeżenie: (0%)
-----


nie wiem czy dobrze zrozumialem:

Kod
foreach($offers -> offer as $offer){
      echo '<b>Nazwa:</b> '.$offer -> name.'<br />';
       echo '<b>Cena:</b> '.$offer -> price.'<br />';
       echo '<b>WWW:</b> '.$offer -> url.'<br />';
       echo '<b>Kategoria:</b> '.$offer -> categoryId.'<br />';
       [b]echo '<b>Zdjęcie:</b> '.$offer -> <img src="image. />'<br /><br />'; [/b]


w pogrubionej linijce wywala mi blad syntax...
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 25.07.2025 - 09:43