Venom Posted February 19, 2003 Report Share Posted February 19, 2003 Ar XML esmu tikai uzsācis. Mēģināju ielikt iekš php, a viš dzen (un ne jau budismu), ka xml-am nepatīk <?, jo tas lūk piederošot viņam. Kas ir mēģinājis šos nezvērus iejūgt vienos ratos, pastāsti savu experience. Link to comment Share on other sites More sharing options...
laacz Posted February 19, 2003 Report Share Posted February 19, 2003 <?='<?xml version="1.0" encoding="utf-8" ?>'?> Link to comment Share on other sites More sharing options...
Venom Posted February 19, 2003 Author Report Share Posted February 19, 2003 bzz! To jau var vienkārši pirms <html> ieraxtīt, bet kā būs, kad iekš php-faila jāraksta kādas apply-templates direktīvas? resp. <?[phpcode]?>[html]<?[xml/xhtml/xsl/xltcode]?>[html]<?[phpcode]?>[html] Link to comment Share on other sites More sharing options...
kits Posted February 19, 2003 Report Share Posted February 19, 2003 kā ar <?php priekš php un <? - xml? Link to comment Share on other sites More sharing options...
Venom Posted February 19, 2003 Author Report Share Posted February 19, 2003 a) <?php 2lame4me B) tik un tā - ja php pratīs atšķirt <?php no <?, tad xml nē. Link to comment Share on other sites More sharing options...
Roze Posted February 19, 2003 Report Share Posted February 19, 2003 Hmm a kaada dalja XML gar php tagiem (begin/end)? PHP ir parseris znachit vinjsh pirmais nodarisies un vinjam varetu buut problemas ar to <?xml un nekaa savadaak.. utt.. ja nu galiigi '2lame4you' tad enablo asp_tags = On un raksti <% blabla; %> Link to comment Share on other sites More sharing options...
jb4 Posted February 28, 2003 Report Share Posted February 28, 2003 Kāpēc jādrukā tas <? xml ... ???? Ja jau esat aizdomājušies līdz XML, tad pēdējais laiks iebraukt šablonos. Defaultais HTML liekams šablonfailā. Šablonu apstrādātājs meklē īpašās vietas un tās aizvieto ar vajadzīgo. Teiksim ar {{CHARSET}} apzīmē vietu, kur jāievieto lapas charsets un notiek tas viss ir nasko str_replace(). Mana šablonu klase (vislabākā pasaulē atrodamā): <code><font color="#000000"> <font color="#0000CC"><? </font><font color="#006600">class </font><font color="#0000CC">MyShape </font><font color="#006600">{ var </font><font color="#0000CC">$ROOT </font><font color="#006600">= </font><font color="#CC0000">""</font><font color="#006600">; var </font><font color="#0000CC">$SHAPENAMES </font><font color="#006600">= array(); var </font><font color="#0000CC">$SHAPES </font><font color="#006600">= array(); function </font><font color="#0000CC">MyShape</font><font color="#006600">(</font><font color="#0000CC">$path_to_root</font><font color="#006600">=</font><font color="#CC0000">''</font><font color="#006600">) { </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">ROOT </font><font color="#006600">= </font><font color="#0000CC">$path_to_root</font><font color="#006600">; } function </font><font color="#0000CC">get_shape</font><font color="#006600">(</font><font color="#0000CC">$shape</font><font color="#006600">) { if (isset(</font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">SHAPES</font><font color="#006600">[</font><font color="#0000CC">$shape</font><font color="#006600">])) { return </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">SHAPES</font><font color="#006600">[</font><font color="#0000CC">$shape</font><font color="#006600">]; } else { return(</font><font color="#0000CC">[url=http://lv.php.net/implode]implode[/url]</font><font color="#006600">(</font><font color="#0000CC">[url=http://lv.php.net/file]file[/url]</font><font color="#006600">(</font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">ROOT </font><font color="#006600">. </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">SHAPENAMES</font><font color="#006600">[</font><font color="#0000CC">$shape</font><font color="#006600">]),</font><font color="#CC0000">""</font><font color="#006600">)); } } function </font><font color="#0000CC">new_shape</font><font color="#006600">(</font><font color="#0000CC">$shape_attributes </font><font color="#006600">= array()) { while (list(</font><font color="#0000CC">$shapename</font><font color="#006600">,</font><font color="#0000CC">$shapesource</font><font color="#006600">) = </font><font color="#0000CC">[url=http://lv.php.net/each]each[/url]</font><font color="#006600">(</font><font color="#0000CC">$shape_attributes</font><font color="#006600">)) { </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">SHAPENAMES</font><font color="#006600">[</font><font color="#0000CC">$shapename</font><font color="#006600">] = </font><font color="#0000CC">$shapesource</font><font color="#006600">; } } function </font><font color="#0000CC">insert_values</font><font color="#006600">(</font><font color="#0000CC">$shapename</font><font color="#006600">,</font><font color="#0000CC">$fields_and_values</font><font color="#006600">) { </font><font color="#0000CC">$shape </font><font color="#006600">= </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">get_shape</font><font color="#006600">(</font><font color="#0000CC">$shapename</font><font color="#006600">); while(list(</font><font color="#0000CC">$field_name</font><font color="#006600">,</font><font color="#0000CC">$field_value</font><font color="#006600">) = </font><font color="#0000CC">[url=http://lv.php.net/each]each[/url]</font><font color="#006600">(</font><font color="#0000CC">$fields_and_values</font><font color="#006600">)) { </font><font color="#0000CC">$shape </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/str_replace]str_replace[/url]</font><font color="#006600">(</font><font color="#CC0000">"{"</font><font color="#006600">.</font><font color="#0000CC">[url=http://lv.php.net/strtoupper]strtoupper[/url]</font><font color="#006600">(</font><font color="#0000CC">$field_name</font><font color="#006600">).</font><font color="#CC0000">"}"</font><font color="#006600">,</font><font color="#0000CC">$field_value</font><font color="#006600">,</font><font color="#0000CC">$shape</font><font color="#006600">); } </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">SHAPES</font><font color="#006600">[</font><font color="#0000CC">$shapename</font><font color="#006600">] = </font><font color="#0000CC">$shape</font><font color="#006600">; } function </font><font color="#0000CC">make_list</font><font color="#006600">(</font><font color="#0000CC">$childname</font><font color="#006600">,</font><font color="#0000CC">$data</font><font color="#006600">) { </font><font color="#0000CC">$mothershape </font><font color="#006600">= </font><font color="#CC0000">""</font><font color="#006600">; foreach (</font><font color="#0000CC">$data </font><font color="#006600">as </font><font color="#0000CC">$record</font><font color="#006600">) { </font><font color="#0000CC">$temp_shape </font><font color="#006600">= </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">get_shape</font><font color="#006600">(</font><font color="#0000CC">$childname</font><font color="#006600">); while(list(</font><font color="#0000CC">$field_name</font><font color="#006600">,</font><font color="#0000CC">$field_value</font><font color="#006600">) = </font><font color="#0000CC">[url=http://lv.php.net/each]each[/url]</font><font color="#006600">(</font><font color="#0000CC">$record</font><font color="#006600">)) { </font><font color="#0000CC">$temp_shape </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/str_replace]str_replace[/url]</font><font color="#006600">(</font><font color="#CC0000">"{"</font><font color="#006600">.</font><font color="#0000CC">[url=http://lv.php.net/strtoupper]strtoupper[/url]</font><font color="#006600">(</font><font color="#0000CC">$field_name</font><font color="#006600">).</font><font color="#CC0000">"}"</font><font color="#006600">,</font><font color="#0000CC">$field_value</font><font color="#006600">,</font><font color="#0000CC">$temp_shape</font><font color="#006600">); } </font><font color="#0000CC">$mothershape </font><font color="#006600">.= </font><font color="#0000CC">$temp_shape</font><font color="#006600">; } return </font><font color="#0000CC">$mothershape</font><font color="#006600">; } function </font><font color="#0000CC">make_simple_list</font><font color="#006600">(</font><font color="#0000CC">$childname</font><font color="#006600">,</font><font color="#0000CC">$data</font><font color="#006600">,</font><font color="#0000CC">$indicator</font><font color="#006600">) { </font><font color="#0000CC">$mothershape </font><font color="#006600">= </font><font color="#CC0000">""</font><font color="#006600">; foreach (</font><font color="#0000CC">$data </font><font color="#006600">as </font><font color="#0000CC">$record</font><font color="#006600">) { </font><font color="#0000CC">$temp_shape </font><font color="#006600">= </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">get_shape</font><font color="#006600">(</font><font color="#0000CC">$childname</font><font color="#006600">); </font><font color="#0000CC">$temp_shape </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/str_replace]str_replace[/url]</font><font color="#006600">(</font><font color="#CC0000">"{"</font><font color="#006600">.</font><font color="#0000CC">[url=http://lv.php.net/strtoupper]strtoupper[/url]</font><font color="#006600">(</font><font color="#0000CC">$indicator</font><font color="#006600">).</font><font color="#CC0000">"}"</font><font color="#006600">,</font><font color="#0000CC">$record</font><font color="#006600">,</font><font color="#0000CC">$temp_shape</font><font color="#006600">); </font><font color="#0000CC">$mothershape </font><font color="#006600">.= </font><font color="#0000CC">$temp_shape</font><font color="#006600">; } return </font><font color="#0000CC">$mothershape</font><font color="#006600">; } function </font><font color="#0000CC">end_parse</font><font color="#006600">(</font><font color="#0000CC">$shapename</font><font color="#006600">) { </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">SHAPES</font><font color="#006600">[</font><font color="#0000CC">$shapename</font><font color="#006600">] = </font><font color="#0000CC">[url=http://lv.php.net/ereg_replace]ereg_replace[/url]</font><font color="#006600">(</font><font color="#CC0000">"{[A-Z_]+}"</font><font color="#006600">,</font><font color="#CC0000">""</font><font color="#006600">,</font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">get_shape</font><font color="#006600">(</font><font color="#0000CC">$shapename</font><font color="#006600">)); } function </font><font color="#0000CC">print_shape</font><font color="#006600">(</font><font color="#0000CC">$name</font><font color="#006600">) { if (isset(</font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">SHAPES</font><font color="#006600">[</font><font color="#0000CC">$name</font><font color="#006600">])) { echo </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">SHAPES</font><font color="#006600">[</font><font color="#0000CC">$name</font><font color="#006600">]; } } </font><font color="#0000CC">?> </font>}</font> </code> Šeit apskatāms šablonfaili: Pirmais: pamats.tpl <code><font color="#000000"> <html> <head> <title>{LAPAS_VIRSRAKSTS}</title> </head> <body> {LAPAS_VIRSRAKSTS} {SATURS} </body> </html></font> </code> Otrais (viena raksta šablons): raksts.tpl <code><font color="#000000"> <div style="padding: 10px; font-size: 90%;"> <b>{VIRSRAKSTS}</b><br /> {TEKSTS} </div></font> </code> Un tagad šablonu izmantošana sekojoša rakstu masīva parādīšanai: ($raksti definīcijas vietā varēja būt mysql_get_assoc() no atlasītiem MySQL rezultātiem) <code><font color="#000000"> <font color="#0000CC"><? $raksti</font><font color="#006600">=array( array(</font><font color="#CC0000">'virsraksts'</font><font color="#006600">=></font><font color="#CC0000">'Ekonomiskā krīze Valmierā'</font><font color="#006600">, </font><font color="#CC0000">'teksts'</font><font color="#006600">=></font><font color="#CC0000">'Šodien Valmierā cenas stāvus gaisā'</font><font color="#006600">), array(</font><font color="#CC0000">'virsraksts'</font><font color="#006600">=></font><font color="#CC0000">'Apsveicam!'</font><font color="#006600">, </font><font color="#CC0000">'teksts'</font><font color="#006600">=></font><font color="#CC0000">'Apsveicam Pēteri Rūjienā deviņdesmitajos šūpuļsvētkos!'</font><font color="#006600">), array(</font><font color="#CC0000">'virsraksts'</font><font color="#006600">=></font><font color="#CC0000">'Pāvilostā dzelzceļnieku streiks'</font><font color="#006600">, </font><font color="#CC0000">'teksts'</font><font color="#006600">=></font><font color="#CC0000">'Pāvilostas dzelzceļnieku arodbiedrība pieteikusi streiku' </font><font color="#006600">)); require_once(</font><font color="#CC0000">'myshape.class.php'</font><font color="#006600">); </font><font color="#0000CC">$lapa </font><font color="#006600">= new </font><font color="#0000CC">MyShape</font><font color="#006600">(</font><font color="#CC0000">'home/www/sabloni/'</font><font color="#006600">); </font><font color="#0000CC">$lapa</font><font color="#006600">-></font><font color="#0000CC">new_shape</font><font color="#006600">(array( </font><font color="#CC0000">'pamatsablons'</font><font color="#006600">=></font><font color="#CC0000">'pamats.tpl'</font><font color="#006600">, </font><font color="#CC0000">'viena_raksta_sablons'</font><font color="#006600">=></font><font color="#CC0000">'raksts.tpl' </font><font color="#006600">)); </font><font color="#0000CC">$lapa</font><font color="#006600">-></font><font color="#0000CC">insert_values</font><font color="#006600">(</font><font color="#CC0000">'pamatsablons'</font><font color="#006600">,array( </font><font color="#CC0000">'lapas_virsraksts'</font><font color="#006600">=></font><font color="#CC0000">'Novadu ziņas'</font><font color="#006600">, </font><font color="#CC0000">'saturs'</font><font color="#006600">=></font><font color="#0000CC">$lapa</font><font color="#006600">-></font><font color="#0000CC">make_list</font><font color="#006600">(</font><font color="#CC0000">'viena_raksta_sablons'</font><font color="#006600">,</font><font color="#0000CC">$raksti</font><font color="#006600">) )); </font><font color="#0000CC">$lapa</font><font color="#006600">-></font><font color="#0000CC">end_parse</font><font color="#006600">(</font><font color="#CC0000">'pamatsablons'</font><font color="#006600">); echo </font><font color="#0000CC">$lapa</font><font color="#006600">-></font><font color="#0000CC">get_shape</font><font color="#006600">(</font><font color="#CC0000">'pamatsablons'</font><font color="#006600">); </font><font color="#0000CC">?></font> </font> </code> Koda izpildes rezultātā vajadzētu iegūt HTML failu: <code><font color="#000000"> <html> <head> <title>Novadu ziņas</title> </head> <body> <div style="padding: 10px; font-size: 90%;"> <b>Ekonomiskā krīze Valmierā</b><br /> Šodien Valmierā cenas stāvus gaisā </div> <div style="padding: 10px; font-size: 90%;"> <b>Apsveicam!</b><br /> Apsveicam Pēteri Rūjienā deviņdesmitajos šūpuļsvētkos! </div> <div style="padding: 10px; font-size: 90%;"> <b>Pāvilostā dzelzceļnieku streiks</b><br /> Pāvilostas dzelzceļnieku arodbiedrība pieteikusi streiku </div> </body> </html></font> </code> Un tas ir viss. Dizaineriem dodam šablonus, paši ķeramies pie kodiem. Link to comment Share on other sites More sharing options...
Venom Posted March 17, 2003 Author Report Share Posted March 17, 2003 Nu, attālināšos no šabloniem un tomēr par to php+xml; Uzliku tomēr short_tags=off; <?xml ...> <?xml stylesheet ...> <body> <?php echo 'php strādā'; ?> </body> Lieta tāda, ka diezgan grūti dabūt nopārsēt ar xsl:template, ja fails beidzas ar *.php. Izdevās to izdarīt, ieliekot php lapas augšā header("Content-type: text/xml"); Bet tagad atkal viss tiek ļoti stipri "pieskatīts" un, ja php izraksta, piem. kādu ' ', lapas contents vairs nerādās (pie am pārsvarā nevis izmetot xml-warningu, bet vienkārši tuxha lapa). Vai nevarētu uztaisīt tā, lai tas viss varētu būt "non-valid", bet tomēr rādītos? Link to comment Share on other sites More sharing options...
skalpelis Posted March 27, 2003 Report Share Posted March 27, 2003 Ja galīgi lauž, var jau vienkārši noehot to "<?" <code><font color="#000000"> <font color="#0000CC"><? </font><font color="#006600">echo </font><font color="#CC0000">'<?xml version="1.0" encoding="utf-8" ?>'</font><font color="#006600">; </font><font color="#0000CC">?> </font> </font> </code> Link to comment Share on other sites More sharing options...
jannis Posted March 27, 2003 Report Share Posted March 27, 2003 paldies jb4 par shablonu kodu, tieshaam vienkaarshi :) tagad tik jaasagaida kaads labs raksts par xml. to, kas ir xml apmeeram saprotu, bet gribeetu uzzinaat siikaak ko un kaa (un nesuutiet mani uz googli vai kur citur; ko lai dara cilveeks, kam inets tikai lv zonaa?!) Link to comment Share on other sites More sharing options...
Venom Posted March 27, 2003 Author Report Share Posted March 27, 2003 ir www.google.lv un "Saglabātā versija". Var palīdzēt. Link to comment Share on other sites More sharing options...
jannis Posted March 28, 2003 Report Share Posted March 28, 2003 vobshem www.google.lv neiet :( jaa tad es veel gribeeju pajautaat par tiem shabloniem. tas viss kods jauki straadaa, bet kaa labaak riikoties, ja es piemeeram gibu kaadu {ASDF} aizvietot ar faila saturu? Link to comment Share on other sites More sharing options...
jb4 Posted March 28, 2003 Report Share Posted March 28, 2003 <code><font color="#000000"> <font color="#0000CC"><?php </font><font color="#006600">require_once(</font><font color="#CC0000">'myshape.class.php'</font><font color="#006600">); </font><font color="#0000CC">$lapa </font><font color="#006600">= new </font><font color="#0000CC">MyShape</font><font color="#006600">(</font><font color="#CC0000">'home/www/sabloni/'</font><font color="#006600">); </font><font color="#0000CC">$lapa</font><font color="#006600">-></font><font color="#0000CC">new_shape</font><font color="#006600">(array( </font><font color="#CC0000">'pamatsablons'</font><font color="#006600">=></font><font color="#CC0000">'pamats.tpl'</font><font color="#006600">, </font><font color="#CC0000">'iipashais_fails'</font><font color="#006600">=></font><font color="#CC0000">'fails.php' </font><font color="#006600">)); </font><font color="#0000CC">$lapa</font><font color="#006600">-></font><font color="#0000CC">insert_values</font><font color="#006600">(</font><font color="#CC0000">'pamatsablons'</font><font color="#006600">,array( </font><font color="#CC0000">'asdf'</font><font color="#006600">=></font><font color="#0000CC">$lapa</font><font color="#006600">-></font><font color="#0000CC">get_shape</font><font color="#006600">(</font><font color="#CC0000">'iipashais_fails'</font><font color="#006600">) )); </font><font color="#0000CC">$lapa</font><font color="#006600">-></font><font color="#0000CC">end_parse</font><font color="#006600">(</font><font color="#CC0000">'pamatsablons'</font><font color="#006600">); echo </font><font color="#0000CC">$lapa</font><font color="#006600">-></font><font color="#0000CC">get_shape</font><font color="#006600">(</font><font color="#CC0000">'pamatsablons'</font><font color="#006600">); </font><font color="#0000CC">?> </font> </font> </code> Link to comment Share on other sites More sharing options...
Roze Posted April 1, 2003 Report Share Posted April 1, 2003 ir www.google.lv un "Saglabātā versija". Var palīdzēt. google.lv diemzheel nav LV zonaa un tas rosina domu par saitu/proxy -> google priekshj LV useriem .. Link to comment Share on other sites More sharing options...
v3rb0 Posted June 17, 2003 Report Share Posted June 17, 2003 Mana šablonu klase (vislabākā pasaulē atrodamā): vai http://smarty.php.net esi redzējis :rolleyes: Link to comment Share on other sites More sharing options...
Recommended Posts