PHP回声一大块文字 [英] PHP Echo a large block of text
问题描述
我是PHP新手,我无法弄清楚使用echo函数的规则是什么。例如,如果我需要回显大块的css / js,是否需要在每行文本中添加回显或者是否有方法用单个回显回显大块代码?
Im new to PHP and I can't figure out what the rules are for using the echo function. For example, if I need to echo a large block of css/js, do I need to add echo to each line of text or is there a way to echo a large block of code with a single echo?
当我尝试回显一个像这样的大块代码时,出现错误:
When I try to echo a big block of code like this one, I get an error:
if (is_single()) {
echo '<link type="text/css" rel="stylesheet" href="http://jotform.com/css/styles/form.css"/><style type="text/css">
.form-label{
width:150px !important;
}
.form-label-left{
width:150px !important;
}
.form-line{
padding:10px;
}
.form-label-right{
width:150px !important;
}
body, html{
margin:0;
padding:0;
background:false;
}
.form-all{
margin:0px auto;
padding-top:20px;
width:650px !important;
color:Black;
font-family:Verdana;
font-size:12px;
}
</style>
<link href="http://jotform.com/css/calendarview.css" rel="stylesheet" type="text/css" />
<script src="http://jotform.com/js/prototype.js" type="text/javascript"></script>
<script src="http://jotform.com/js/protoplus.js" type="text/javascript"></script>
<script src="http://jotform.com/js/protoplus-ui.js" type="text/javascript"></script>
<script src="http://jotform.com/js/jotform.js?v3" type="text/javascript"></script>
<script src="http://jotform.com/js/location.js" type="text/javascript"></script>
<script src="http://jotform.com/js/calendarview.js" type="text/javascript"></script>
<script type="text/javascript">
JotForm.init(function(){
$('input_6').hint('ex: myname@example.com');
});
</script>';
}else {
}
有没有更好的方法如何在没有太多工作的情况下回应大块代码(例如,为每行添加回显)?解决方案
Is there a better way to echo large blocks of code without a lot of work (adding echo to each line for example)?
解析方案
使用你的代码,在你的if语句的大括号之后,结束PHP:
With your code, after the opening curly brace of your if statement, end the PHP:
if (is_single()) { ?>
然后删除 echo'
和';
毕竟你的html和css,在关闭之前}
,写:
After all your html and css, before the closing }
, write:
<? } else {
如果要写入页面的文本是动态的, ,但现在这应该工作得很好。
If the text you want to write to the page is dynamic, it gets a little trickier, but for now this should work fine.
这篇关于PHP回声一大块文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!