Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Php, xml polskie znaki - rozdzielanie
kill15
post
Post #1





Grupa: Zarejestrowani
Postów: 184
Pomógł: 14
Dołączył: 21.12.2010

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


Mam taki kod php:

  1. <?php
  2.  
  3. class BadParser
  4. {
  5.  
  6. function BadParser ()
  7. {
  8.  
  9. $parser = xml_parser_create();
  10.  
  11. //This is the RIGHT WAY to set everything inside the object.
  12. xml_set_object ( $parser, $this );
  13.  
  14. xml_set_element_handler ( $parser, 'tagStart', 'tagEnd' );
  15. xml_set_character_data_handler ( $parser, 'tagContent' );
  16.  
  17. xml_parse ( $parser, $this->XMLData );
  18.  
  19. if (!($fp = fopen('test.xml', "r"))) {
  20. die("could not open XML input");
  21. }
  22.  
  23. while ($data = fread($fp, 409600)) {
  24. if (!xml_parse($parser, $data, feof($fp))) {
  25. die(sprintf("XML error: %s at line %d",
  26. xml_error_string(xml_get_error_code($parser)),
  27. xml_get_current_line_number($parser)));
  28. }
  29. }
  30.  
  31.  
  32. }
  33.  
  34. function tagStart ( $parser, $tagName, $attributes = NULL )
  35. {
  36.  
  37. $this->tag = $tagName;
  38.  
  39. }
  40.  
  41. function tagEnd ( $parser, $tagName )
  42. {
  43.  
  44. $this->tag = NULL;
  45.  
  46. }
  47. public $table = array();
  48. function tagContent ( $parser, $content )
  49. {
  50. echo '<pre>';
  51.  
  52. echo $content;
  53.  
  54.  
  55. }
  56.  
  57. }
  58. $aa = new BadParser;
  59.  
  60. ?>


wszystko byłoby dobrze gdyby nie polskie otóż:
gdy w xmlu mam np coś takiego:

<name> nazwa mała</name>

to w tablicy $content mam to jako 2 różne elementy tj. :
[0] => nazwa ma
[1] => ła

co mam zrobić aby nie robiło mi oddzielnych elementów tylko: [0] => nazwa mała

PS: all w utf-8 nagłowek xmla też

Ten post edytował kill15 15.11.2011, 21:46:11
Go to the top of the page
+Quote Post
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Nie polecam parsować w ten sposób. Użyj simplexml a już najlepiej to DomDocument
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 24.08.2025 - 10:36