Aikss Posted March 22, 2008 Report Share Posted March 22, 2008 (edited) Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /some/path on line 61 60. $replacement = '<span style="color: blue;">$1$2$3</span>'; 61. $date = preg_replace($pattern, $replacement, $date); 62. tukša līnija 63. /* = = */ Zīme '&' failā parādās pie foreach ( $array as &$value ) un vēl vairākās vietās šādi $pattern = '/(<!DOCTYPE){1,1}(.*)("){1,1}/'; Uz localhost viss iet, bet ieliekot uz servera met erroru! UZ MISKASTI! Noņēmu no foreach visur nost. Bāc sākumā noņēmu no diviem, bet bija tak vel trešais foreach. Edited March 22, 2008 by Aikss Link to comment Share on other sites More sharing options...
bubu Posted March 22, 2008 Report Share Posted March 22, 2008 Visdrīzāk uz servera ir php4, bet tev ir php5. Uzliec sev tieši tādu pašu versiju kā tādu, kāda ir uz servera. Būs mazāk problēmu. Link to comment Share on other sites More sharing options...
Aikss Posted March 22, 2008 Author Report Share Posted March 22, 2008 Paldies bubu. Tik tiešām tur 4 man 5. Tas laikam ir problemātiski serverī pārlikt php versijas, būs jāuzjautā administratoram. Man ir neskaidrība ar to foreach. Viņā parādās mainīgais $value - foreach ( $array as $value ), bet viņš izraisa error. Uz php5 uzliku zīmi & un itkā iet, bet uz php4.4.2 error. Kā lai viņu piedabū pie dzīvības uz php4.4.2 Link to comment Share on other sites More sharing options...
bubu Posted March 22, 2008 Report Share Posted March 22, 2008 Atkarībā no tā, ko tu ar to $value tur dari. Vai pats vispār saproti, ko tas & tajā vietā dara? Ja nē, tad iesaku atvērt foreach manuāļa lapu un saprast. Link to comment Share on other sites More sharing options...
Aikss Posted March 22, 2008 Author Report Share Posted March 22, 2008 (edited) As of PHP 5, you can easily modify array's elements by preceding $value with &. This will assign reference instead of copying the value. Jāņem talkā vārdnīca - modify array's elements by preceding $value with &. $value tiek apstrādāta ar preg_replace. Taisu xhtml un php koda iekrāsošanu. Uz php5 ar zīmi & viss strādā, bez zīmes strādā tikai funkcija neizpilda savu uzdevumu - kaut kas ar foreach. Uz php4 ar zīmi & errors bez funkcija neizpilda savu uzdevumu. Edited March 22, 2008 by Aikss Link to comment Share on other sites More sharing options...
bubu Posted March 22, 2008 Report Share Posted March 22, 2008 Ar foreach tam visam ir tikai otršķirīgis sakars. Svarīgāk, atkārtojos, ir tas, ko un kā tu dari ar $value mainīgo. Link to comment Share on other sites More sharing options...
Aikss Posted March 22, 2008 Author Report Share Posted March 22, 2008 (edited) function php_color($date) { foreach($date as &$value) { if ( preg_match("/^(\/\/ ){1,1}/", $value) == '1' ) { $pattern = '/(\/\/.*)/'; $replacement = "<span class=\"coment\">$1</span>"; $value = preg_replace($pattern, $replacement, $value); } else { $pattern = '/("{1,1}([^"]*[a-zA-Z0-9 <>\\?$_\-\/.;:]*)*("){1,1}){1,5}/'; $replacement = '<span style="color: red">$1</span>'; $value = preg_replace($pattern, $replacement, $value); $pattern = '/([^\/])((\'{1,1})([^\'][0-9a-zA-Z\/-_\;\: \.\*\=]*)(\'{1,1}))/'; $replacement = '$1<span style="color: red">$2</span>'; $value = preg_replace($pattern, $replacement, $value); } } return $date; } ko un kā tu dari ar $value mainīgo. Nesaprotu, ko tu centies pateikt. Iespaidojies esmu no šī: $arr = array(1, 2, 3, 4); foreach ($arr as &$value) { $value = $value * 2; } // $arr is now array(2, 4, 6, 8) Edited March 22, 2008 by Aikss Link to comment Share on other sites More sharing options...
bubu Posted March 22, 2008 Report Share Posted March 22, 2008 Vajag nevis iespaidoties, bet saprast kā un kāpēc tas strādā. function php_color($date) { $result = array(); foreach($date as $value) { if ( preg_match("/^(\/\/ ){1,1}/", $value) == '1' ) { $pattern = '/(\/\/.*)/'; $replacement = "<span class=\"coment\">$1</span>"; $value = preg_replace($pattern, $replacement, $value); } else { $pattern = '/("{1,1}([^"]*[a-zA-Z0-9 <>\\?$_\-\/.;:]*)*("){1,1}){1,5}/'; $replacement = '<span style="color: red">$1</span>'; $value = preg_replace($pattern, $replacement, $value); $pattern = '/([^\/])((\'{1,1})([^\'][0-9a-zA-Z\/-_\;\: \.\*\=]*)(\'{1,1}))/'; $replacement = '$1<span style="color: red">$2</span>'; $value = preg_replace($pattern, $replacement, $value); } $result[] = $value; } return $result; } Link to comment Share on other sites More sharing options...
Aikss Posted March 22, 2008 Author Report Share Posted March 22, 2008 Liels paldies bubu! Vajag nevis iespaidoties, bet saprast kā un kāpēc tas strādā. Kā rādās diezko labi jau nesanāk, bet centīšos. Link to comment Share on other sites More sharing options...
bubu Posted March 22, 2008 Report Share Posted March 22, 2008 Lūdzu. Link to comment Share on other sites More sharing options...
Recommended Posts