Jump to content


Photo

Unexpected T_STRING... But why?


  • Please log in to reply
2 replies to this topic

#1 DeathRay2K

DeathRay2K
  • Members
  • 96 posts
  • Location:Canada
  • Projects:D2K Studios, Xaeon Mod, Unseen Presence, Rhythm Mixer, Website Designs, CSS OS

Posted 10 January 2006 - 03:50 AM

I made a simple function to check a filename to see if there was |Category, |Subcategory, or something else, but nearly everyy line is generating errors...
11	function whatis($name){
12  $checktype = explode('|', $name);
13  $checkfile = explode('.', $name);
14  if(count($checktype) >=2 && $checktype[1] == 'Category')
15  	return 'Category';
16  elseif(count($checktype) >=2 && $checktype[1] == 'Subcategory')
17  	return 'Subcategory';
18  elseif(count($checkfile) <= 3)
19  	return 'File';
20  else
21  	return 'Undesirable';
22	}
I wrote the line number before each line... This error starts at line 14, but even if I remove everything in the if statement after >=2, line 15 errors:
Parse error: parse error, unexpected T_STRING in /my/website/foo/bar/script.php on line 14

I feel like something's really stupid in my code, but I'm just too tired to find it... :)

#2 DCoder

DCoder

    One of the Few

  • Members
  • 331 posts
  • Location:Lithuania, Central Europe
  •  Old Grumpy Bastard

Posted 10 January 2006 - 06:57 AM

Works fine over here... (PHP 5.1.1)

echo whatis('foo.txt'); spits out "File".

echo whatis('foo|Category|foo.txt'); spits out "Category".

echo whatis('foo|Subcategory|foo.txt'); spits out "Subcategory";

But you should enclose the if/else in curly brackets. Or use the alternative synta.
Ares - How do you want to improve YR today?
What's stopping you from migrating to Ares? We can't implement it unless you tell us!

ModEnc - C&C Modding Encyclopedia | Modders' Quote Database | Yet Another C&C Modding Forum

#3 DeathRay2K

DeathRay2K
  • Members
  • 96 posts
  • Location:Canada
  • Projects:D2K Studios, Xaeon Mod, Unseen Presence, Rhythm Mixer, Website Designs, CSS OS

Posted 10 January 2006 - 10:05 PM

Thanks for the help DCoder. I figured out the problem, I'd accidentally skipped the closequotes on a string. :umad:
I normally do enclose ifs in curly brackets, I was just being a bit lazy. :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users