Say I have a block of code I would like to test like this:
<?php
Print "Hello, World!";
?>
How I quickly run this code from terminal without saving it to a file?
I tried things like…
php -r "Print "Hello, World!";"
but just got complaints about syntax errors. There has to be a simple way of doing this. I just have yet to find any explanations.
Escape the inside double quotes (
") that you are using to delimit your string.Alternatively, use single quotes (
') for the PHP string or for the quoting of the PHP code.If you run
php --helpyou can see a list of commands that thephpprogram accepts.