php.net manual example giving "unexpected T_Variable

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

pict3000
New php-forum User
New php-forum User
Posts: 1
Joined: Sat Feb 01, 2014 8:24 am

php.net manual example giving "unexpected T_Variable

Postby pict3000 » Sat Feb 01, 2014 8:39 am

When I try to run the example code below from the GD documentation for the imagecreatetruecolor() function at php.net, I get "unexpected T_VARIABLE" on the line where the $gd variable is set to the above function. But I don't see any semicolons or brackets omitted. So I don't get it. Here's the code:

Code: Select all

<?php

$x = 200;
$y = 200;

$gd = imagecreatetruecolor($x, $y);
 
$corners[0] = array('x' => 100, 'y' =>  10);
$corners[1] = array('x' =>   0, 'y' => 190);
$corners[2] = array('x' => 200, 'y' => 190);

$red = imagecolorallocate($gd, 255, 0, 0);

for ($i = 0; $i < 100000; $i++) {
  imagesetpixel($gd, round($x),round($y), $red);
  $a = rand(0, 2);
  $x = ($x + $corners[$a]['x']) / 2;
  $y = ($y + $corners[$a]['y']) / 2;
}
 
header('Content-Type: image/png');
imagepng($gd);

?>


My server has gd enabled and my web page is test.php, so can anyone spot my problem?

Here's the original link to that php.net example, if that will help you:

http://www.php.net/manual/en/function.imagesetpixel.php

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests