Checking Syntax Error in PHP from Command Line

July 31st, 2012 by Laeeq | 3 comments

PHP allows you to check your script syntax without running the code. Just use the – l switch with php command. It will check the syntax error in your script and show the “Unexpected token …” error message if there is any syntax error in your script.

Here First we will create a  php file “Hello.php”

  1. <?php
  2. echo “\n Hello PHP! \n”;
  3. ?>

Command to check syntax errors in your PHP script:

  1. $ php -l hello-world.php

Below is the screen that showing running php command with error messages.

php check error

You can subscribe to PHPZAG.COM posts by Email

 

Related Topics:

  • Wrapping Text using PHP
  • PHP 5.5 beta 4 is now available
  • Swapping Array Keys and Values
  • PHP Security
  • Working with Image Metadata in PHP
  • Converting Between Relative and Absolute File Path
  • Parsing File Paths with PHP
  • How to remove HTML Comments with PHP?
  • How to access .htaccess values?
  • Dealing With Common PHP Errors
  • Interview Questions and Answers for Freshers
  • Display numbers with ordinal suffix using PHP
  • Function to set COLLATION on database fields of Mysql
  • Read and write to remote files using PHP
  • Sharing PHP SESSION Variables between Multiple Subdomains
  • PHP 5.5.0 Alpha4 Development Preview Released
  • Check a string starts with http using PHP
  • Cross-Site Scripting Attacks (XSS)
  • PHP 5.4.11 and PHP 5.3.21 released!
  • PHP Memory Leak Issue
  •  

     

    1. Jhon
      August 1st, 2012 at 13:30 | #1

      nice post!

    2. smith
      August 1st, 2012 at 13:31 | #2

      better way to know HTMl markup, thanks..keep it up

    3. techstyle
      August 1st, 2012 at 13:37 | #3

      really fantastic job…keep it up!

    1. No trackbacks yet.