[英]Inline PHP Tag not closing
I have included php in html to change the background image according to some variables. 我在html中包含了php来根据一些变量更改背景图像。 Thus i am calling
img-set()
function in body tag. 因此我在body标签中调用
img-set()
函数。 The function is working fine. 功能正常。 But the html code breaks after the function has been run.
但是在运行该函数后,html代码会中断。 I think it's some syntax problem not able to it figure out.
我认为这是一些无法弄清楚的语法问题。
<body style="background:url(images/<?php $obj->set_img();?>); -webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover;background-size: cover;">
The output in source code of web browser looks like: Web浏览器源代码中的输出如下所示:
<body style="background:url(images/music7.jpg
This break after displaying image name. 显示图像名称后中断。 Why so ??
为什么这样 ??
Here, is the set_img() function 这里是set_img()函数
function set_img()
{
$ctr = date("d");
$arr7 = array("7","18","29");
$status = 0;
foreach($arr7 as $value){
if($ctr == $value){
echo "music7.jpg";
$status = 7;
}}
if(!$status) echo "music1.jpg";
}
使用<?php set_img();?>
不<?php $obj->set_img();?>
There's probably a problem with your set_img() function causing the rest of the page to stop rendering. 你的set_img()函数可能存在问题,导致页面的其余部分停止渲染。 Look at the code after you output the image.
输出图像后查看代码。 A quick test to see if the error is due to your function is to remove that php block and see if the page renders fine.
快速测试以查看错误是否是由您的函数引起的是删除该php块并查看该页面呈现是否正常。
<body style="background:url(images/<?php set_img();?>); -webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover;background-size: cover;">
I think there is an unrendered exception too. 我认为还有一个没有发现的例外。
But when I watch the set_img function, I cannot imagine how it could throw any exception. 但是当我观察set_img函数时,我无法想象它是如何抛出任何异常的。 May be $obj is not instanciate with the right class ?
可能是$ obj是不是与正确的班级同步?
Sounds like a silent PHP error. 听起来像一个无声的PHP错误。 It can be difficult to detect sometimes.
有时可能很难检测到。 Try checking your Apache error logs at
/var/log/Apache2
and it should say what error is causing PHP to break. 尝试检查
/var/log/Apache2
的Apache错误日志,它应该说明导致PHP崩溃的错误。
I think you may be missing quotes around your url. 我想你的网址可能会丢失引号。 Try:
尝试:
<body style="background:url('imges/music7.jpg')">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.