doumen9709 2014-04-27 14:53
浏览 29
已采纳

在变量中写入变量而不识别它

Just a quick question. I'm having trouble with writing variable ($var) just as text, example:

$header = "

<?php
$title ='title';
$work = 'work';
$about = 'about';
$contact = 'contact';
?>

";

and now I should be ablw to echo it as it is. But I get errors that those variables are not defined.

  • 写回答

1条回答 默认 最新

  • douleng0794 2014-04-27 14:55
    关注

    Variables in double quoted strings in PHP are interpolated. Escape the dollar signs.

    $header = "
    
    <?php
    \$title ='title';
    \$work = 'work';
    \$about = 'about';
    \$contact = 'contact';
    ?>
    
    ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?