8
Thanks

A few words of thanks would be greatly appreciated.

PHP - Parse error, unexpected T_STRING, expecting ',' or ';'

T_String is the common parse error associated with the creation of PHP files. This problem is observed when an apostrophe sign is added in between a code that has been delimited with apostrophes, generating huge conflict with the PHP document.



How to Ignore an Apostrophe in PHP

To ignore an apostrophe within a PHP code, a slash must be inserted in front of the apostrophe excluded from the command. A PHP error also arises when a ';' sign is not inserted at the end of the command. PHPbeing a program demands a logical flow of commands. This is the simple step that needs to be taken to avoid T_String parse errors while coding PHP commands.

PHP File Creation Problem

A common problem that may arise while creating a PHP file is the parse error T_String. This happens when an apostrophe is entered in a series of codes already being delimited by apostrophes. Having several apostrophes in the same command creates a huge conflict within the PHP document.

Example 1

<?   
echo 'we don't know';
?>

Solve the Problem

The above example can be solved simply by telling the program where to ignore the apostrophe, by inserting a slash before the apostrophe that is not being used as a command. Hence, the code above will be written as:
<?   
echo 'we don\t know';
?>

Example 2

The Parse Error can also arise if the programmer has forgotten to insert the ; symbol at the end of the command.
<?
echo 'we \"don't\" know'   
?>

Note: PHP is a simple program that asks for much attention. You should not have any problem with it if you pay enough attention to the logical flow of the program.

Image: © Arian Darvishi - Unsplash.com
8
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Related

This document, titled « PHP - Parse error, unexpected T_STRING, expecting ',' or ';' », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

0 Comments