darklow Posted March 13, 2003 Report Share Posted March 13, 2003 kaa php aatraak parsee kodu, gadiijumos, kad echojam kaadu lielaaku gabalu teksta, un ir nepiecieshams pa vidu ielikt if? 1) piem: <code><font color="#000000"> <font color="#0000CC"><? </font><font color="#006600">echo</font><font color="#CC0000">'txt xtx txt xtx'</font><font color="#006600">; if(</font><font color="#0000CC">$a</font><font color="#006600">)echo</font><font color="#CC0000">'bla'</font><font color="#006600">; echo</font><font color="#CC0000">'txt txt txt txt'</font><font color="#006600">; </font><font color="#0000CC">?> </font> </font> </code> 2) vai arii aatraak tiek parseets shaadi: <code><font color="#000000"> <font color="#0000CC"><? </font><font color="#006600">echo</font><font color="#CC0000">'txt xtx txt xtx'</font><font color="#006600">.(</font><font color="#0000CC">$a</font><font color="#006600">?</font><font color="#CC0000">'bla'</font><font color="#006600">:</font><font color="#CC0000">''</font><font color="#006600">).</font><font color="#CC0000">'txt txt txt txt'</font><font color="#006600">; </font><font color="#0000CC">?> </font> </font> </code> Link to comment Share on other sites More sharing options...
jb4 Posted March 13, 2003 Report Share Posted March 13, 2003 Pirmais: <code><font color="#000000"> <font color="#0000CC"><?php $jurka </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/microtime]microtime[/url]</font><font color="#006600">(); </font><font color="#0000CC">$a </font><font color="#006600">= </font><font color="#0000CC">false</font><font color="#006600">; echo</font><font color="#CC0000">'txt xtx txt xtx'</font><font color="#006600">; if(</font><font color="#0000CC">$a</font><font color="#006600">)echo</font><font color="#CC0000">'bla'</font><font color="#006600">; echo</font><font color="#CC0000">'txt txt txt txt'</font><font color="#006600">; echo </font><font color="#0000CC">[url=http://lv.php.net/microtime]microtime[/url]</font><font color="#006600">()-</font><font color="#0000CC">$jurka</font><font color="#006600">; </font><font color="#0000CC">?> </font> </font> </code> Otrais: <code><font color="#000000"> <font color="#0000CC"><?php $jurka </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/microtime]microtime[/url]</font><font color="#006600">(); </font><font color="#0000CC">$a </font><font color="#006600">= </font><font color="#0000CC">false</font><font color="#006600">; echo</font><font color="#CC0000">'txt xtx txt xtx'</font><font color="#006600">.(</font><font color="#0000CC">$a</font><font color="#006600">?</font><font color="#CC0000">'bla'</font><font color="#006600">:</font><font color="#CC0000">''</font><font color="#006600">).</font><font color="#CC0000">'txt txt txt txt'</font><font color="#006600">; echo </font><font color="#0000CC">[url=http://lv.php.net/microtime]microtime[/url]</font><font color="#006600">()-</font><font color="#0000CC">$jurka</font><font color="#006600">; </font><font color="#0000CC">?> </font> </font> </code> Pirmajam vidēji 0.000185 Otrajam - 0.000192 (jeb pareizāk sakot starpības nava) Tev tjipa microtime() nav uzinstalēts vai arī gribējās kaut ko tāpat vien iepostēt?????????? Link to comment Share on other sites More sharing options...
Smejmoon Posted March 14, 2003 Report Share Posted March 14, 2003 <code><font color="#000000"> txt xtx txt xtx <font color="#0000CC"><?</font><font color="#006600">if(</font><font color="#0000CC">$a</font><font color="#006600">) echo</font><font color="#CC0000">'bla'</font><font color="#006600">;</font><font color="#0000CC">?> </font>txt txt txt txt </font> </code> Link to comment Share on other sites More sharing options...
jb4 Posted March 14, 2003 Report Share Posted March 14, 2003 <code><font color="#000000"> <font color="#0000CC"><?php </font><font color="#FF9900">/* PHP optimization version 1.0 task: output "txt txt txt bla txt txt txt" if $a is true or output "txt txt txt txt txt txt" if $a is false */ </font><font color="#0000CC">[url=http://lv.php.net/session_start]session_start[/url]</font><font color="#006600">(); if (!</font><font color="#0000CC">[url=http://lv.php.net/headers_sent]headers_sent[/url]</font><font color="#006600">()) { </font><font color="#0000CC">[url=http://lv.php.net/header]header[/url]</font><font color="#006600">(</font><font color="#CC0000">'Content-type: text/html'</font><font color="#006600">); } </font><font color="#0000CC">[url=http://lv.php.net/set_magic_quotes_runtime]set_magic_quotes_runtime[/url]</font><font color="#006600">(</font><font color="#0000CC">0</font><font color="#006600">); </font><font color="#0000CC">[url=http://lv.php.net/set_time_limit]set_time_limit[/url]</font><font color="#006600">(</font><font color="#0000CC">60</font><font color="#006600">); </font><font color="#0000CC">[url=http://lv.php.net/ob_start]ob_start[/url]</font><font color="#006600">(</font><font color="#CC0000">'ob_gzhandler'</font><font color="#006600">); </font><font color="#0000CC">prestring</font><font color="#006600">(); </font><font color="#0000CC">$a </font><font color="#006600">= </font><font color="#0000CC">false</font><font color="#006600">; </font><font color="#FF9900">// var pamainīt uz true arī </font><font color="#006600">if (isset(</font><font color="#0000CC">$a</font><font color="#006600">) && </font><font color="#0000CC">$a</font><font color="#006600">==</font><font color="#0000CC">false</font><font color="#006600">) { if (isset(</font><font color="#0000CC">$a</font><font color="#006600">)==</font><font color="#0000CC">false</font><font color="#006600">) { die(</font><font color="#CC0000">"Can't perform performance test - important setting not found"</font><font color="#006600">); } } else { echo </font><font color="#0000CC">[url=http://lv.php.net/strtolower]strtolower[/url]</font><font color="#006600">(</font><font color="#CC0000">'BLA '</font><font color="#006600">); } </font><font color="#0000CC">prestring</font><font color="#006600">(); </font><font color="#0000CC">[url=http://lv.php.net/ob_end_flush]ob_end_flush[/url]</font><font color="#006600">(); function </font><font color="#0000CC">prestring</font><font color="#006600">() { </font><font color="#0000CC">$init </font><font color="#006600">= array(</font><font color="#CC0000">'t'</font><font color="#006600">, </font><font color="#CC0000">'e'</font><font color="#006600">, </font><font color="#CC0000">'x'</font><font color="#006600">, </font><font color="#CC0000">'t'</font><font color="#006600">, </font><font color="#CC0000">'i'</font><font color="#006600">, </font><font color="#CC0000">'l'</font><font color="#006600">, </font><font color="#CC0000">'s'</font><font color="#006600">); </font><font color="#0000CC">$arr1 </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/array_shift]array_shift[/url]</font><font color="#006600">(</font><font color="#0000CC">$init</font><font color="#006600">); </font><font color="#0000CC">$arr2 </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/array_slice]array_slice[/url]</font><font color="#006600">(</font><font color="#0000CC">$init</font><font color="#006600">, </font><font color="#0000CC">[url=http://lv.php.net/intval]intval[/url]</font><font color="#006600">(</font><font color="#0000CC">1</font><font color="#006600">), </font><font color="#0000CC">4</font><font color="#006600">-</font><font color="#0000CC">2</font><font color="#006600">); </font><font color="#0000CC">$string </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/implode]implode[/url]</font><font color="#006600">(</font><font color="#CC0000">' '</font><font color="#006600">, </font><font color="#0000CC">$arr2</font><font color="#006600">); </font><font color="#0000CC">$arr3 </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/array_merge]array_merge[/url]</font><font color="#006600">(</font><font color="#0000CC">$arr1</font><font color="#006600">,</font><font color="#0000CC">[url=http://lv.php.net/explode]explode[/url]</font><font color="#006600">(</font><font color="#CC0000">' '</font><font color="#006600">, </font><font color="#0000CC">$string</font><font color="#006600">)); </font><font color="#0000CC">$finalstring </font><font color="#006600">= </font><font color="#CC0000">''</font><font color="#006600">; for (</font><font color="#0000CC">$i</font><font color="#006600">=</font><font color="#0000CC">1</font><font color="#006600">; </font><font color="#0000CC">$i</font><font color="#006600"><</font><font color="#0000CC">[url=http://lv.php.net/abs]abs[/url]</font><font color="#006600">(</font><font color="#0000CC">[url=http://lv.php.net/sqrt]sqrt[/url]</font><font color="#006600">(</font><font color="#0000CC">16</font><font color="#006600">)); </font><font color="#0000CC">$i</font><font color="#006600">++) { if (isset(</font><font color="#0000CC">$arr3</font><font color="#006600">[</font><font color="#0000CC">$i</font><font color="#006600">-</font><font color="#0000CC">1</font><font color="#006600">])) { </font><font color="#0000CC">$finalstring </font><font color="#006600">.= </font><font color="#0000CC">$arr3</font><font color="#006600">[</font><font color="#0000CC">$i</font><font color="#006600">-</font><font color="#0000CC">1</font><font color="#006600">]; } } </font><font color="#0000CC">$y </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/date]date[/url]</font><font color="#006600">(</font><font color="#CC0000">'m'</font><font color="#006600">); </font><font color="#FF9900">/* strādās tikai martā (aprīlī var pielikt klāt date('m')-1) gan jau maijam un citiem mēnešiem arī ir kaut kādi workaroundi. ja baigi vajag, var ar Googli atrast */ </font><font color="#0000CC">$temp </font><font color="#006600">= </font><font color="#0000CC">0</font><font color="#006600">; while (</font><font color="#0000CC">$temp</font><font color="#006600"><</font><font color="#0000CC">$y</font><font color="#006600">) { echo </font><font color="#0000CC">$finalstring</font><font color="#006600">; echo </font><font color="#CC0000">' '</font><font color="#006600">; </font><font color="#0000CC">$temp</font><font color="#006600">++; } } </font><font color="#0000CC">?> </font> </font> </code> Testēts uz PHP 4.3.0 (Windows mašīna, Apache). Strādā ātri un precīzi. Link to comment Share on other sites More sharing options...
Recommended Posts