Parse Error: Unexpected $end

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jaguar
Forum Newbie
Posts: 5
Joined: Thu Dec 25, 2003 10:40 pm
Contact:

Parse Error: Unexpected $end

Post 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
User avatar
swirlee
Forum Newbie
Posts: 7
Joined: Fri Dec 26, 2003 12:08 am

Post 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.
Jaguar
Forum Newbie
Posts: 5
Joined: Thu Dec 25, 2003 10:40 pm
Contact:

still nothing

Post 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.
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post 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..
Jaguar
Forum Newbie
Posts: 5
Joined: Thu Dec 25, 2003 10:40 pm
Contact:

Parse Error: Unexpected $end

Post by Jaguar »

no, the while statement is correct, they all match up
Jaguar
Forum Newbie
Posts: 5
Joined: Thu Dec 25, 2003 10:40 pm
Contact:

Parse Error: Unexpected $end

Post 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
Jaguar
Forum Newbie
Posts: 5
Joined: Thu Dec 25, 2003 10:40 pm
Contact:

Parse Error: Unexpected $end

Post 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
Post Reply