Timur Fayzrakhmanov
Timur Fayzrakhmanov

Reputation: 19587

How to run the blocks of code in cli? PHP

In several online resources I've seen the examples like in the picture below. So, How can I run it? Is it possible?

I know about interactive mode (php -a) or run code without using script tags (php -r), but all of them differ from example below..

enter image description here

Upvotes: 0

Views: 119

Answers (3)

ray
ray

Reputation: 4267

ctrl + D is something new to me
To run simple code in php, I used to use php -r

php -r 'for ($i=0; $i<3; $i++) { echo $i . "\n"; }'

Upvotes: 0

rid
rid

Reputation: 63442

One way would be from stdin:

echo '<?php echo "hello world!"; ?>' | php

Another way would be to use Ctrl + D:

$ php

<?php
echo "hello world!\n";
?>
^D
hello world
$

Upvotes: 1

&#193;lvaro Gonz&#225;lez
&#193;lvaro Gonz&#225;lez

Reputation: 146450

Ctrl+D if I recall correctly. That's the Unix shortcut for EOF (end of file).

It's normally easier to just use files.

Upvotes: 3

Related Questions