0

These lines are causing a syntax/parse error, and I'm not sure how to fix it. I'm pretty sure it's either the <?php and ?> tags, or the single quotes. Any ideas?

$data = '<?php
    $title = "'. $name. '";
    $keywords = "'. $title. ','. $developer. '";
    $description = "How to install '. $title. ' for PC and Mac.";

    include('templates/modheader.php');
    include('templates/modfooter.php');
    ?>';

Thanks in advance.

7
  • 2
    What are you trying to do? Commented Dec 18, 2013 at 23:52
  • It's more likely to be the fact that you're not escaping the ' around your included filenames Commented Dec 18, 2013 at 23:53
  • 1
    Consider a HEREDOC string. Commented Dec 18, 2013 at 23:56
  • @arielcr It's a variable to create a file. Yes, the formatting is a bit strange. Commented Dec 18, 2013 at 23:57
  • 1
    Nothing about this looks like anything a sane person should ever actually put into production. Stop. Rethink. Rewrite. Commented Dec 19, 2013 at 0:05

3 Answers 3

3
include('templates/modheader.php');
include('templates/modfooter.php');

is the culprit: You mix single quotes. SImply use

include("templates/modheader.php");
include("templates/modfooter.php");
Sign up to request clarification or add additional context in comments.

Comments

0
include('templates/modheader.php');
include('templates/modfooter.php');

should be

include("templates/modheader.php");
include("templates/modfooter.php");

Comments

0

For large blocks of string data, I highly recommend the HEREDOC / NOWDOC syntax. You can combine that with sprintf to inject values

$template = <<<'_PHP'
<?php
$title = '%s';
$keywords = $title . ',%s';
$description = "How to install $title for PC and Mac.";

include 'templates/modheader.php';
include 'templates/modfooter.php';
?>
_PHP;

$data = sprintf($template, $name, $developer);

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.