How to check PHP syntax using the command line

If you’re using PHP for web developoment, you may often want to check the syntax of your file without opening it in a browser. Checking syntax is quite easy from the command line.

Tools:

  • 1 ea shell
  • 1 ea PHP

1Open Terminal or any other unix shell

If you’re on a Mac you can open Terminal which is located in: Applications/Utilities

2Navigate to your project folder

You can navigate to your project folder by using the change directory or cd command followed by the directory. For me it is: cd /Users/josephtylerjones/Developer/scripts/

3Use the php command with the -l option

Now you can check the syntax of your script by running php -l followed by the file name. For me it is: php -l testfile.php This command will detect any syntax errors in your script!


Now learn about:


Discuss this guide

var disqus_shortname = ‘howchootest’; (function() { var dsq = document.createElement(‘script’); dsq.type = ‘text/javascript’; dsq.async = true; dsq.src = ‘//’ + disqus_shortname + ‘.disqus.com/embed.js’; (document.getElementsByTagName(‘head’)[0] || document.getElementsByTagName(‘body’)[0]).appendChild(dsq); })();

Tools:

  • 1 ea shell
  • 1 ea PHP

Leave a Reply

Your email address will not be published. Required fields are marked *