By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

php -r

P: n/a
Does anyone have a simple example of using 'php -r <code>' ?

I had thought that this would work...

C:\>php -r echo "test";
PHP Parse error: syntax error, unexpected $end in Command line code
on line 1

But as you can see, it doesn't. I've tried Google'ing the answer to no
avail.

I'm using Windows/Apache/MySQL and:

PHP 5.2.5 (cli) (built: Nov 8 2007 23:18:51)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
Daniel Klein
Jan 6 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Daniel Klein wrote:
Does anyone have a simple example of using 'php -r <code>' ?

I had thought that this would work...

C:\>php -r echo "test";
PHP Parse error: syntax error, unexpected $end in Command line code
on line 1

But as you can see, it doesn't. I've tried Google'ing the answer to no
avail.

I'm using Windows/Apache/MySQL and:

PHP 5.2.5 (cli) (built: Nov 8 2007 23:18:51)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
Daniel Klein
Not sure but shouldn't there be some <? ?pairs in there somewhere?

Jan 6 '08 #2

P: n/a
On Sun, 06 Jan 2008 15:27:17 +0100, Daniel Klein
<da*****@featherbrain.netwrote:
Does anyone have a simple example of using 'php -r <code>' ?

I had thought that this would work...

C:\>php -r echo "test";
PHP Parse error: syntax error, unexpected $end in Command line code
on line 1
As always, if you have a space in your command line argument, you should
quote it, so either:
php -r "echo 'test';"

or

php -r echo('test');

--
Rik Wasmus
Jan 6 '08 #3

P: n/a
Not sure but shouldn't there be some <? ?pairs in there somewhere?

No, there should never be any <? ?around anywhere. Shorttags are evil.
Jan 6 '08 #4

P: n/a
Daniel Klein wrote:
I had thought that this would work...

C:\>php -r echo "test";
You need to escape certain characters from the shell. For most Linux
shells you could use:

php -r echo\ \"test\"\;

or (slightly easier on the eye):

php -r 'echo "test";'

Not sure what it would be on Windows, but give those two a whirl.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 7 days, 2:22.]

dhyana.pl/0.3
http://tobyinkster.co.uk/blog/2008/01/06/dhyana/
Jan 6 '08 #5

P: n/a
php -r 'echo "test";'
>
Not sure what it would be on Windows, but give those two a whirl.
On windows, change the quotes:
php -r "echo 'test';"
Jan 6 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.