Run simple php functions direct on command line

If you want to run/test oneliners in PHP on the command line you can use the -r option.

php -r 'echo "Hello World";' 

Will simply output “Hello World” on the command line

I sometimes use this method to test regexp expressions

php -r 'echo preg_match("/^Test/", "This is a test");'

Here I check if $string starts with the string ‘Test’ (the answer is no).

Using onliners on the command line can sometimes be very handy

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

This site uses Akismet to reduce spam. Learn how your comment data is processed.