Hari Krishna Ganji
Hari Krishna Ganji

Reputation: 1677

How to use php-cli in interactive mode, in Ubuntu?

I wanted to quick test a small snippet of PHP code. So, After doing a little search I setup php5-cli using synaptic on my Ubuntu machine.

Now when I tried to run

$ php -a

I get a php prompt. But I am unable to get it to work. I tried :

php > echo 'hi there!'
    >
    >

php > <?php echo 'hi there!' ?>
    > 
    >

But, nothing seems to work! What am I doing wrong?

[Note: I am not very familiar with PHP]

[Update :

I wish to achieve something like :

    php > $url = myurl
    > $ch = curl_init();
    > curl_setopt($ch, CURLOPT_URL, $url);
    > $body = curl_exec($ch);
    > curl_close($ch);
    > 
    > echo $body

]

Upvotes: 1

Views: 1649

Answers (2)

maxjackie
maxjackie

Reputation: 23282

It will work like this:

php -r "echo 'hello';"

Upvotes: 1

Mark Reed
Mark Reed

Reputation: 95252

You need to terminate your statements with a semicolon.

php > echo "hello"
php > ;
hello
php > echo "oh!";
oh!
php > 

Upvotes: 2

Related Questions