PHP echo在echo中 [英] PHP echo in echo
本文介绍了PHP echo在echo中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像这样的字符串:
I have a string that looks like this:
<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陈述来回应这一点.例如:
However, I want to echo this with an if statment. For example:
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>';
}
问题在于这将无法正常工作,因为原始字符串中已经包含了回显.我该如何解决?
The problem is that this will not work, because the original string already has an echo in it. How can I get around this?
推荐答案
为实现此目的,您应该连接字符串.在这种情况下,您在函数周围有两个字符串-但是该函数返回一个字符串,因此将它们全部串联在一起是完全有效的.
In order to achieve this you should concatenate your strings. In this case you have two strings surrounding a function - but that function returns a string so it is perfectly valid to just concatenate them all together.
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>';
}
这篇关于PHP echo在echo中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文