2

I'm editing the functions.php file of a WordPress theme and whenever I edit it, even when the edit is adding a single space the server returns

error:

Parse error: syntax error, unexpected '}' in /theme/functions.php on line 1     

This is where I add the single space:

<?php load_theme_textdomain('theme', get_template_directory() . '/languages'); 
 <— I added a single space here

and everything dies after that. This is not a consistent error, as it goes away after I replace the whole functions.php file itself with a backed up one. It only is replicated when I edit the file, that is, as presented even with single white-space character. I'm using NetBeans and CuteFTP to edit then upload the files.

What is going on?! This must have to do with some kind of file quality itself, since from a code standpoint the code is exactly the same...or maybe my server.

Solution:
Netbeans defaults to a specific file encoding per project. Foreign files may have a different encoding which may cause problems. Cody the foreign file's contents to a new blank file which you created via Netbeans.

Mohammad
  • 7,344
  • 15
  • 48
  • 76
  • Is this a single line of PHP or is there more? If more, please show. – Jonathan M Sep 13 '11 at 17:16
  • Yup, you should include more lines. – ajreal Sep 13 '11 at 17:19
  • It's small but is there anywhere like JSFiddle that I could upload it? Thank you! – Mohammad Sep 13 '11 at 17:20
  • Just the first 10 lines will do. If we want more, we'll ask. :) – Jonathan M Sep 13 '11 at 17:20
  • Link to the source of the file: http://codepad.org/gCoKbM0q – Mohammad Sep 13 '11 at 17:23
  • My confusion is when the error doesn't go away when I delete the space, and why does it have to appear on a simple extra space entry on the first place? Is it my server? – Mohammad Sep 13 '11 at 17:25
  • Puzzler. One unrelated(?) weirdness is: `register_sidebar(array('name'=>'Sidebar',));` Why the comma after `'Sidebar'`? – Jonathan M Sep 13 '11 at 17:30
  • I tried to edit that out in my own copy as well. But this file cant be touched! – Mohammad Sep 13 '11 at 17:31
  • @Jonathan M: I found [this question](http://stackoverflow.com/questions/1929026/how-to-fix-the-invisible-space-problem-in-php) could it be related? I just don't understand completely what they're saying though. – Mohammad Sep 13 '11 at 17:32
  • You mean you get errors if you edit out the comma? What about taking out one of the asterisks in `/***********`. Does that also cause it? – Jonathan M Sep 13 '11 at 17:32
  • No, even with the fresh working file from the backup, adding a single space in NetBeans + uploading it to the server causes the error. – Mohammad Sep 13 '11 at 17:34

2 Answers2

3

It could be an encoding error. Maybe when you try to edit the file your text editor is including a UTF-8 BOM at the top.

EDIT

Just found instructions for saving as UTF-8 without BOM in Notepad++:

1) Click on "Format" Select "Encode in UTF-8 without BOM"

2) Click on "settings" Click on "Preferences" Click on "new document/open save directory" Select "UTF-8 without BOM"

(Source: http://www.phpbb.com/community/viewtopic.php?f=66&t=1584655#p9490925, 5th answer from the bottom)

But the encoding you need to set really depends on the original file. If it's not UTF-8, you should keep the original encoding (Latin 1 or whatever).

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
  • Correct, when I edit the file in Notepad++ the error doesn't happen. It must be Netbeans? What specifically am I trying to avoid here, could you point me to the right direction so I can find the appropriate NetBeans settings. : ) Thank you! – Mohammad Sep 13 '11 at 17:37
  • I mean, which format do I need to save PHP files in as default? Thank you. – Mohammad Sep 13 '11 at 17:39
  • Edited my answer with instructions for Notepad++ – bfavaretto Sep 13 '11 at 17:49
  • I found something that works with Netbeans as well, since Netbeans defaults to the same encoding per project, foreign files may cause these errors. Making a new file within Netbeans and naming it the same, and copy + pasting all the previous files contents solves the issue altogether. – Mohammad Sep 13 '11 at 18:00
0

Are you including it in the right place? See http://codex.wordpress.org/Function_Reference/load_theme_textdomain

BenjaminRH
  • 11,974
  • 7
  • 49
  • 76