Jump to content

Unexpected T_STRING... But why?


DeathRay2K

Recommended Posts

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  else21 	 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

Link to comment
Share on other sites

Don't see anything out of place.Maybe you have an escaped quote or something before the function.No warnings or errors with your function:

<?php function whatis($name){  $checktype = explode('|', $name);  $checkfile = explode('.', $name);  if(count($checktype) >=2 && $checktype[1] == 'Category')   return 'Category';  elseif(count($checktype) >=2 && $checktype[1] == 'Subcategory')   return 'Subcategory';  elseif(count($checkfile) <= 3)   return 'File';  else   return 'Undesirable'; } $str = "One|Category|Three";echo "<p>". whatis($str) ."</p>";$str = "One|Subcategory|Three";echo "<p>". whatis($str) ."</p>";$str = "One.Two.Three";echo "<p>". whatis($str) ."</p>";$str = "One.Two.Three.Four.Five";echo whatis($str);?>

You will have to keep looking for the culprit.I guess you have already tried commenting blocks of your code.

Link to comment
Share on other sites

Yes, that's how I noticed that the error just moves to the next line when I comment strings out...And unfortunately there are no problems like that in my script, they'd be easy to fix...I also tried changing it to this:

11	function whatis($name){12  if(substr_count($name, '|Category')>0)13 	 return "Category";14  elseif(substr_count($name, '|Subcategory')>0)15 	 return "Subcategory";16  elseif(is_file($name))17 	 return "File";18  else19 	 return "Undesirable";20	}

But then instead of an unexpected T_STRING I get unexpected T_CONSTANT_ENCAPSED_STRING on line 14...Maybe it doesn't like | in a string? But that doesn't make much sense... :(Edit:Wait, I did, in fact have an escaped quote! :) Thanks for the help! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...