Page 1 of 1

Parse Error: Unexpected $end

Posted: Thu Dec 25, 2003 10:40 pm
by Jaguar
a php newb here, I just finished basic syntax and other random sections on php.net in about a day, so I have very little experience with this particular langauge. the problem being is that I've run through my code many times over and I still can't seem to decipher why it's spitting the error "Parse Error: parse error, Unexpected End in \lib\pdatproc.php on line 41" back at me when I go to include this single function inhabitted library I wrote into some other script. If anyone could help me, I'd be appreciative. Here's the code in pdatproc.php -

Code: Select all

<?php
	function poll() &#123;
		$pollFile = 'currpoll';
		$pollDir = 'e:\domains\a\home\alcothology.com\databin'';
		if (isset($_GET&#1111;"sub"])) &#123;
			header("location: vio.php?err=poll");
		&#125;
		$fp = fopen(($pollDir.$pollFile), "r");
		if (!$fp) &#123;
			$arr = array("penpen" => 0, "wraither" => 0, "either" => 0);
			$tmpfp = fopen(($pollDir.$pollFile), "w");
			fputs($tmpfp, implode(",", $arr);
			fclose($tmpfp);
		&#125; 
		else &#123;
			while (($char = fgetc($fp)) != false) &#123;
				$buffer .= $char;
			&#125;
			$arr = explode(",", $buffer);
			fclose($fp);
		&#125;
		switch ($_POST&#1111;"poll"]) &#123;
			case 1:
				$arr&#1111;"penpen"]++;
				break;
			case 2:
				$arr&#1111;"wraither"]++;
				break;
			case 3:
				$arr&#1111;"either"]++;
				break;
			default:
				header("location: vio.php?err=poll");
				break;
		&#125;
		$tmpfp = fopen(($pollDir.$pollFile), "w");
		fputs($tmpfp, implode(",", $arr));
		fclose($tmpfp);
		print_r($arr);
	&#125;
?> // <-- line 41

Posted: Fri Dec 26, 2003 12:08 am
by swirlee
What a difference a character makes. Your problem is way up on line 12:

Code: Select all

<?php
fputs($tmpfp, implode(",", $arr); 
?>
Unmatched parentheses. Pretty impressive that it didn't trip up PHP until way down on line 41, but it's funky like that sometimes.

still nothing

Posted: Fri Dec 26, 2003 8:09 am
by Jaguar
That was probably one of the errors that was keeping it back, but it's still giving me the same parse error, only one line down (line 42) which is blank.

Posted: Fri Dec 26, 2003 8:20 am
by aquila125
another one:

while (($char = fgetc($fp)) != false)


get yourself an editor that shows the parentheses that corresponds with the current one (crimsoneditor eg)... much easier to detect these mistakes..

Parse Error: Unexpected $end

Posted: Fri Dec 26, 2003 8:38 am
by Jaguar
no, the while statement is correct, they all match up

Parse Error: Unexpected $end

Posted: Fri Dec 26, 2003 8:46 am
by Jaguar
apparently line 4 was giving the parser trouble (single quoted directory literal) so I used double quotes and escaped all the backslashes and the unexpected $end error disappeared, but now it's complaining about line 5. when will this end? lol

Parse Error: Unexpected $end

Posted: Fri Dec 26, 2003 8:48 am
by Jaguar
w00t, success
thanks for all the contribution. Apparently I didn't close line 4 with double quotes (which I noticed seconds after my last post). One I fixed that problem, the script runs fine. danke sehr