0

I want to print php tags in php file so I am using

$variable="<?php   
include("./$folder/$folder.php"); 
?>";
echo "$variable";

but its giving me error

Parse error: syntax error, unexpected T_STRING

3
  • Most IDEs provide syntax highlighting which help to indicate concatenation errors like this. Check out NetBeans or Eclipse (they're both free to download and use), or even Dreamweaver (which is available for a license fee). Commented Aug 29, 2012 at 18:57
  • echo "$variable; is a syntax error. echo $variable Commented Aug 29, 2012 at 18:58
  • @karthikr I fixed it but this is not the actual problem but I am trying to echo php tags <?php ?> in php file so its giving me error Commented Aug 29, 2012 at 19:00

1 Answer 1

4

You need to escape the double quotes using the backslash character (\):

$variable="<?php   
include(\"./$folder/$folder.php\"); 
?>";

You can also clean up your echo expression by dropping the unnecessary quotes:

echo $variable;
Sign up to request clarification or add additional context in comments.

5 Comments

This will also interpolate the variable $folder - It is unclear whether or not this is desired behavior.
its not about double quotes (this is also a problem) but I am trying to echo php tags <?php ?> in php file so its giving me error
@user1613566: You'll need to pass the variable through the htmlentities function for the tags to be displayed properly.
@TimCooper Make that htmlspecialchars()
Alternatively, for the quick and dirty, you can represent your open and close angle brackets as &lt; and &gt; ie: echo "&lt;php ...";

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.