Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> simplexml_load_file & simplexml_load_string, czy te funkcje są zamienne?
morrison
post
Post #1





Grupa: Zarejestrowani
Postów: 117
Pomógł: 0
Dołączył: 24.05.2004
Skąd: krakow

Ostrzeżenie: (10%)
X----


wiec myslalem ze maja one to samo dzialanie, ale chyba tak nie jest do konca. otoz mam kod:

  1. <?php
  2. $xmlstr = <<<XML
  3. <?xml version='1.0' standalone='yes'?>
  4. <a>
  5. <bibtex>
  6. <title>
  7. bib1
  8. </title>
  9. </bibtex>
  10. <bibtex>
  11. <title>
  12. bib2
  13. </title>
  14. </bibtex>
  15. <bibtex>
  16. <title>
  17. bib3
  18. </title>
  19. </bibtex>
  20. </a>
  21. XML;
  22. $xml = simplexml_load_string($xmlstr);
  23. echo $xml->bibtex[1]->title;
  24.  
  25. ?>


dziala to poprawnie. Jednak ja musze miec kod xml'a dolaczony jako osobny plik, wiec prubuje uzyc
funkcji simplexml_load_file ale za jej pomoca nie udaje mi sie to. czy ktos potrafi mi pokazac jak zastapic moj kod funkcja simplexml_load_file tak zeby uzyskac ten sam efekt??


--------------------
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


A czytales manual o tych funkcjach?

simplexml_load_string wczytuje XMLa ze zmiennej, tu: $xmlstr
simplexml_load_file -- z pliku (podajesz jego nazwe).

Ewentualnie mozesz uzyc
simplexml_load_string() + file_get_contents().


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
morrison
post
Post #3





Grupa: Zarejestrowani
Postów: 117
Pomógł: 0
Dołączył: 24.05.2004
Skąd: krakow

Ostrzeżenie: (10%)
X----


sprobowalem tak:
  1. <?php
  2.  
  3. ?php
  4. if (file_exists('./edytor/test.xml')) {
  5.  $xmlstr = file_get_contents('./edytor/test.xml');
  6. var_dump($xmlstr);
  7. } else {
  8.  exit('Failed to open file!');
  9. }
  10. $xml = simplexml_load_string($xmlstr);
  11. echo $xml->movie[0]->plot;
  12. ?>


i wywalil bledy:

Kod
string(708) "     Ms. Coder  Onlivia Actora    Mr. Coder  El ActÓr     So, this language. It\'s like, a programming language. Or is it a scripting language? All is revealed in this thrilling horror spoof of a documentary.   7  5  "
Warning: Entity: line 1: parser error : String not started expecting ' or " in /home/osa/public_html/projekt/test2.php on line 10

Warning: in /home/osa/public_html/projekt/test2.php on line 10

Warning: ^ in /home/osa/public_html/projekt/test2.php on line 10

Warning: Entity: line 1: parser error : Malformed declaration expecting version in /home/osa/public_html/projekt/test2.php on line 10

Warning: in /home/osa/public_html/projekt/test2.php on line 10

Warning: ^ in /home/osa/public_html/projekt/test2.php on line 10

Warning: Entity: line 1: parser error : Blank needed here in /home/osa/public_html/projekt/test2.php on line 10

Warning: in /home/osa/public_html/projekt/test2.php on line 10

Warning: ^ in /home/osa/public_html/projekt/test2.php on line 10

Warning: Entity: line 1: parser error : parsing XML declaration: '?>' expected in /home/osa/public_html/projekt/test2.php on line 10

Warning: in /home/osa/public_html/projekt/test2.php on line 10
..........i duzo wiecej


nie dziala. wyrzucil na poczatku cala tresc pliku - i bledy, zrobilem to zle?


--------------------
Go to the top of the page
+Quote Post
chmolu
post
Post #4





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 8.10.2004

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


Masz błędnie sformułowany plik XML. Wrzuć cały plik to zobaczymy.
Go to the top of the page
+Quote Post
morrison
post
Post #5





Grupa: Zarejestrowani
Postów: 117
Pomógł: 0
Dołączył: 24.05.2004
Skąd: krakow

Ostrzeżenie: (10%)
X----


plik jest w porzadku wydaje mi sie:
  1. <?xml version='1.0' standalone='yes'?>
  2. <movies>
  3.  <movie>
  4. <title>php: Behind the Parser</title>
  5. <characters>
  6.  <character>
  7.  <name>Ms. Coder</name>
  8.  <actor>Onlivia Actora</actor>
  9.  </character>
  10.  <character>
  11.  <name>Mr. Coder</name>
  12.  <actor>El ActÓr</actor>
  13.  </character>
  14. </characters>
  15. <plot>
  16.  So, this language. It's like, a programming language. Or is it a
  17.  scripting language? All is revealed in this thrilling horror spoof
  18.  of a documentary.
  19. </plot>
  20. <rating type="thumbs">7</rating>
  21. <rating type="stars">5</rating>
  22.  </movie>
  23. </movies>


nie rozumiem co sie dzieje sad.gif


--------------------
Go to the top of the page
+Quote Post
chmolu
post
Post #6





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 8.10.2004

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


Hmm... trudno powiedzieć. Spróbuj dodać atrybut <?xml encoding="kodowanie"?> i powyłączać magic_quotes_* (o ile są włączone).
Go to the top of the page
+Quote Post
crash
post
Post #7





Grupa: Przyjaciele php.pl
Postów: 2 196
Pomógł: 2
Dołączył: 17.01.2004
Skąd: Sosnowiec

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


A " zamiast ' w deklaracji xml?


--------------------
Go to the top of the page
+Quote Post
morrison
post
Post #8





Grupa: Zarejestrowani
Postów: 117
Pomógł: 0
Dołączył: 24.05.2004
Skąd: krakow

Ostrzeżenie: (10%)
X----


kodowanie dodalem do pliku xml i to nic nie dalo. Natomiast jesli chodzi o magic_quotes to na poczatku bylo tak:
magic_quotes_gpc On On
magic_quotes_runtime On On
magic_quotes_sybase Off Off

teraz dalem tak:
magic_quotes_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off

i bledy zniknely - z tym ze nie ma nadal zamierzonego efektu poniewaz wypisuje sie na ekran zawartosc wszystkich znacznikow z calego pliku!
Dopiero potem wypisuje sie wskazany przeze mnie znacznik:(

Kod
string(616) "     Ms. Coder  Onlivia Actora    Mr. Coder  El ActÓr     So, this language. It's like, a programming language. Or is it a scripting language? All is revealed in this thrilling horror spoof of a documentary.  7  5  " So, this language. It's like, a programming language. Or is it a scripting language? All is revealed in this thrilling horror spoof of a documentary.

to co jest w cudzyslowach to cala zawartosc - nie chciana przeze mnie. dopiero dalszy tekst jest tym co oczekuję. co z tym zrobic?

pomozcie prosze

Ten post edytował morrison 30.08.2005, 16:50:27


--------------------
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 Aktualny czas: 22.08.2025 - 04:30