回声中的PHP回声

时间:2013-03-24 02:55:09

标签: php string echo

我有一个看起来像这样的字符串:

<center>
    <div style="margin-top: 10px; margin-bottom: 10px; font-size: 20px; color: #000; font-weight: bold;">
        <?php echo strlen(file_get_contents('test.txt')); ?> Applications Sent
    </div>
</center>

但是,我想用if语句来回应这个问题。例如:

if ($test == '') { 
    echo '<center><div style="margin-top: 10px; margin-bottom: 10px; font-size: 20px; color: #000; font-weight: bold;"><?php echo strlen(file_get_contents("test.txt")); ?> Applications Sent</div></center>';
}

问题是这不起作用,因为原始字符串中已经有回声。我怎么能绕过这个?

1 个答案:

答案 0 :(得分:6)

为了达到这个目的,你应该连接你的字符串。在这种情况下,你有一个围绕一个函数的两个字符串 - 但该函数返回一个字符串,所以将它们连接在一起是完全有效的。

if ($test == '') { 
    echo '<center><div style="margin-top: 10px; margin-bottom: 10px; font-size: 20px; color: #000; font-weight: bold;">' . strlen(file_get_contents("test.txt")) . ' Applications Sent</div></center>';
}