LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-13-2014, 11:23 AM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Rep: Reputation: 12
PHP Parse error: syntax error, unexpected end of file in Command line code on line 1


This seems ridiculous.

I was in the middle of working out some bugs in another PHP program when I started getting the subject error. I started commenting out portions of the program until I had commentd out everything. Nothing fixed it so I created the code below with the same results.

I am at a standstill. Please help.

Code:
<?php

print "hello rick";

?>
 
Old 05-13-2014, 11:29 AM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Do you mean you created a new file, or are you using the old one?

I would be wary of editing in windows and saving on linux via ftp/scp or whatever. What editor are you using? Have you looked at the contents of the file with vim and turned on view all characters?

In other words, it sounds like an invisible character mucking it up.
 
Old 05-13-2014, 11:44 AM   #3
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
I use Ubuntu 13.04. With Firefox and Bluefish, although I created the sample program with gedit. I don't know a thing about Vim though. No Windows on machine.

Just to be sure about hidden characters I made a new same program. Same results!!
 
Old 05-13-2014, 12:15 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Well if no Windows in the way, may we ask how you are running / viewing / parsing this and where you are getting the error?
 
Old 05-13-2014, 12:26 PM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
> syntax error, unexpected end of file in Command line code on line 1

Please quote the exact command you used.
 
Old 12-11-2014, 09:31 AM   #6
Rechosen
LQ Newbie
 
Registered: Jan 2007
Posts: 19

Rep: Reputation: 0
As this is the top Google result for "unexpected end of file in Command line code", I'll post what fixed this problem for me. It turns out I had placed the option I wanted to pass to my script between "php" and the script filename. Like this
Code:
php -r myscript.php
instead of
Code:
php myscript.php -r
As you work with the command line a lot, you get so used to adding a new option directly after the command name that this is a mistake easily made . Just remove the option between "php" and the script name and re-add it after the script name and you're done!
 
Old 12-11-2014, 12:09 PM   #7
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Your problem was not where the option was placed (php -r myscript.php), it was that that the "-r" option is unnecessary for executing a file.

The "-r" option is for executing code directly. See the man page examples: link
 
Old 12-11-2014, 12:26 PM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
No, this '-r' was not meant for '/usr/bin/php', it was meant for 'myscript.php'.
 
Old 12-11-2014, 12:49 PM   #9
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Whoops. Exposed my lack of reading comprehension.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
diskspace.sh: line 10: syntax error: unexpected end of file sandeepreddy.bommineni Linux - Newbie 2 01-12-2012 05:37 AM
line 23 :syntax error unexpected end of file detected nipuniitg Linux - Software 8 11-13-2011 02:12 PM
Error in Bash: line 77: syntax error: unexpected end of file bribon Programming 8 07-13-2011 12:43 PM
line 313: syntax error: unexpected end of file bes Linux - Newbie 3 05-02-2010 03:32 AM
-bash: *.sh: line 25: syntax error: unexpected end of file prashanth212 Linux - General 8 04-05-2010 11:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration