0

I tried to use short echo tags i.e. <?= ?> to display a string into my PHP file which already has PHP code present within <?php ?> tags. So, I tried to use the short echo tag within my code and got parse error.

See below code :

<?php

 echo 'if you want to serve PHP code in XHTML or XML documents,
       use these tags'; 

 <?= 'While this is going to be parsed.'; ?>

?>

I got following output :

Parse error: syntax error, unexpected '<', expecting end of file in

So, my question is: Are the short echo tags intended to be used only when PHP code is going to embed into HTML code and that's too not within already existing php pair of tags?

Can's I use in a file which contains pure PHP code only?

2
  • why are you using php tag ( <= ) inside another php tag( <?php ) ?? Commented Nov 18, 2017 at 11:50
  • @santosh : To make the code a lot easier to read. Adding Readability to the code is the only reason. Commented Nov 18, 2017 at 11:52

2 Answers 2

2

Yes you can use Short tag in a file which contains pure PHP code only. Here you are using php opening short tag inside php tags, that's why its throwing Parse Error.

if yo want to use, then you should try like below .

<?php

 echo 'if you want to serve PHP code in XHTML or XML documents,
       use these tags'; 
?>
<?= 'While this is going to be parsed.'; ?>
Sign up to request clarification or add additional context in comments.

Comments

0

Use short tag alone. Currently you are using short tag inside php tag. I doesn't cause error if it is used alone in html.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.