Hello EveryOne

I confuse of bellow code

<?php if($True == 0){ ?>
    <a href="/#"> Apply </a>
<?php}else{?>
    <a href="/#"> Aleary applied </a> 
<?php }?>

Given Me Error Parse error: syntax error, unexpected '}'
BUT Solved It: When i replace '<?php' else to '<?' it could be solved.

But why it was Happen i could not understand.
Any One suggest me ?

Thank You.

Dani AI

Generated

A short explanation and practical checks.

A parse error for an unexpected } when switching between PHP and HTML usually means the PHP parser didn’t see a matching opening construct — not that the closing brace itself is wrong. Switching to short tags can hide the real issue rather than fix it. The thread advice about tag placement and spacing from and is useful for readability, but the underlying causes are most often one of the items below.

Common causes and decisive checks:

  • Syntax linting: run php -l path/to/file.php to get the exact syntax error and line number.
  • Unmatched or missing tokens: an if that never executed (because its opening tag wasn’t recognized) makes a later } appear stray; count braces or use an editor/IDE that highlights matching braces.
  • Encoding/BOM: files saved with a UTF‑8 BOM can confuse some environments — save views as UTF‑8 without BOM.
  • Tag configuration: <? depends on the server short_open_tag setting, while full <?php is the portable choice. In CodeIgniter views (plain PHP files) make sure no template preprocessor is changing tags.

A low-friction layout that reduces tag switching is the alternate control-structure syntax; it tends to make mixed PHP/HTML easier to read and less error-prone:

<?php if ($True == 0): ?>
  <a href="/#">Apply</a>
<?php else: ?>
  <a href="/#">Already applied</a>
<?php endif; ?>

The suggestions from about spacing help with visual parsing, but the quickest, most reliable diagnostics are php -l plus checking file encoding and consistent use of full <?php tags. These steps expose whether the problem is a real syntax error, a tag/configuration issue, or an invisible character.

Recommended Answers

All 4 Replies

Member Avatar for Member #46692

line 3 should be <?php else { ?>

I recommend to insert spaces:

<?php if($True == 0){ ?>
    <a href="/#"> Apply </a>
<?php } else { ?>
    <a href="/#"> Aleary applied </a> 
<?php } ?>
commented: @AndrisP : Thank You. +1
Member Avatar for Member #46692

Sorry I was wrong.

good catched AndrisP. Spaces indeed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.