Jump to content
php.lv forumi

Neskaidrība ar error


Aikss
 Share

Recommended Posts

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 by Aikss
Link to comment
Share on other sites

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

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 by Aikss
Link to comment
Share on other sites

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 by Aikss
Link to comment
Share on other sites

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

 Share

×
×
  • Create New...