daktau Posted October 29, 2009 Share Posted October 29, 2009 Hi All, Does anyone know what is causing the error in this code? <? $errorLog_FilePath = "error_log.txt"; $handle = @fopen($errorLog_FilePath,'a+'); $strError = "hi!"; if(!fwrite($handle, $strError)){ //this is line 5 echo('Cannot write to file'); } ?> I get: Parse error: syntax error, unexpected T_VARIABLE on line 5 I can't understand what is wrong with it. thanks a lot, George. Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/ Share on other sites More sharing options...
scvinodkumar Posted October 29, 2009 Share Posted October 29, 2009 this type of error normally occurs only when u forget to add the semicolon( at the end statement. Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/#findComment-946944 Share on other sites More sharing options...
daktau Posted October 29, 2009 Author Share Posted October 29, 2009 this type of error normally occurs only when u forget to add the semicolon( at the end statement. Are not the semi colons all present? Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/#findComment-946983 Share on other sites More sharing options...
Bricktop Posted October 29, 2009 Share Posted October 29, 2009 Hi daktau, Your echo statement is using the incorrect syntax. Change your code to read: <? $errorLog_FilePath = "error_log.txt"; $handle = @fopen($errorLog_FilePath,'a+'); $strError = "hi!"; if(!fwrite($handle, $strError)){ //this is line 5 echo 'Cannot write to file'; } ?> Hope this helps. Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/#findComment-946989 Share on other sites More sharing options...
PFMaBiSmAd Posted October 29, 2009 Share Posted October 29, 2009 The posted code does not produce that error. It is likely that your actual code has something in it, like smart-quotes, that is causing php to see something that it does not expect in a php code file. Are you using a programming editor to write code with? Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/#findComment-946998 Share on other sites More sharing options...
daktau Posted October 29, 2009 Author Share Posted October 29, 2009 <? $errorLog_FilePath = "error_log.txt"; if($handle = @fopen($errorLog_FilePath,'a+')){ $strError = "hi!"; if(!fwrite($handle, 'hi')){ echo('Cannot write to file'); } } ?> This code produces this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in filename.php on line 5 I use EditPlus v3.11 to edit php code. It does not add any of it's own stuff into my code. Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/#findComment-947131 Share on other sites More sharing options...
daktau Posted October 29, 2009 Author Share Posted October 29, 2009 Do you still see no error when running this code in your own environment? Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/#findComment-947180 Share on other sites More sharing options...
PFMaBiSmAd Posted October 29, 2009 Share Posted October 29, 2009 No error. The code you just posted produces a error_log.txt file that contains the word hi. Best guess is that whatever is in the file is being filtered out by the processing that it goes through when it is posted to and displayed on this forum. It is probably the double quotes. Make sure you use the straight " and not any curly/smart quotes. Edit: You could attach your actual file to a post, you could in fact have a broken php installation. Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/#findComment-947224 Share on other sites More sharing options...
daktau Posted October 29, 2009 Author Share Posted October 29, 2009 Thanks, I have changed the quotes to single and I'm saving the file as a utf-8 encoded script. I'm still receiving the error:- Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in D:\rob-l\file_reNamerTEST2.php on line 5 I have attached the file this time. I'm fairly sure that my php installation is running ok as this is the first error of this sort I've ever seen. I was also running the script on a Mac with the php that comes with OSX and it still gave the same error. Do you have any more clues? [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/#findComment-947283 Share on other sites More sharing options...
lemmin Posted October 29, 2009 Share Posted October 29, 2009 <? $errorLog_FilePath = "error_log.txt"; if($handle = @fopen($errorLog_FilePath,'a+')){ $strError = 'hi!'; if(!fwrite($handle, 'hi')){     echo('Cannot write to file'); } } ?> Try editing that file in notepad to remove those funny characters. Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/#findComment-947308 Share on other sites More sharing options...
Andy-H Posted October 29, 2009 Share Posted October 29, 2009 Don't save with the UTF-8 encoding type as it add's a Byte Order Mark to the file. Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/#findComment-947335 Share on other sites More sharing options...
daktau Posted October 30, 2009 Author Share Posted October 30, 2009 Ok, can someone please run this on their system and try and explain why I'm still getting an error on line 5? I have saved the file as ANSI encoded and included it with this post. Can someone explain why if I save the same file with a different encoding it fouls up the php? eg. the server does not interpret the code. Even if I re-save the same file as a file encoding that works it seems to output the file as oriental lettering and does not convert the script. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/#findComment-947771 Share on other sites More sharing options...
lemmin Posted October 30, 2009 Share Posted October 30, 2009 You still have funny characters. Some spaces (that should be ASCII 32) are ASCII 160. Line 4, character 23 (The space right before the $strError) Line 5, characters 4,5,6,7,20,26,29 (All spaces after the first 3) Are you using a foreign keyboard or did you copy this code from somewhere else? Link to comment https://forums.phpfreaks.com/topic/179474-fwrite-error/#findComment-947987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.