Author - StudySection Post Views - 47 views
PHP

PHP Short Open Tags

Some days ago I was doing setup for a project on my local system, I faced many issues due to PHP short open tags. So I’m sharing the fix that worked for me. I hope this can help you all in future.

Introduction:

The <?php is used to recognize the start of a PHP document. In PHP whenever it reads a PHP document, it looks for an opening and closing tags, which are <?php and ?> which tell PHP to start and stop interpreting the code between them. Parsing during this manner allows PHP to be embedded in all sorts of different documents, as everything outside of a pair of opening and closing tags is ignored by the PHP parser.

When we use <? ?> tag is called a short open tag in PHP. PHP also includes a short echo() tag which is a short-hand to the more verbose <?php echo ?> Here I’m sharing the example that produces the same output with and without short open tags. Both of the below codes give us the same output.

Normal Way.
<?php echo $message = "Hello World"; ?>

The ShortHand Way.
<? echo $message = "Hello World"; ?>
or
<?= $message = "Hello World" ?>

Short tags are available by default but can be disabled either via the short_open_tag php.ini configuration file directive or are disabled by default in the configuration.

Solution:

So if you want To use the short tags, one must have a short_open_tag configuration enabled.
First, you need to ensure that short tags are not disabled, in configuration. To check it, go into the php.ini file.

If you are working on Windows you can easily access php.ini through XAMPP. You need to click on the Apache Config tab and you will see a list of configuration files. Here you can find the php.ini file and then open it. Here I’m also sharing a screenshot to understand.
xampp

If you are using a Linux system then here is the php.ini location.
/etc/php5/apache2/php.ini
Then open your php.ini file and Find the below line in the file and add (On) instead of (Off)
short_open_tag=On
So by using the above solution you can use short tags without facing any issues or errors.

Get certification for your knowledge in the fundamentals of Computer functioning by clearing the Computer Certification Exam conducted by StudySection. After going through this Computer Certification exam, you will be able to evaluate your basic knowledge of computers.

Leave a Reply

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