嘿朋友我是php的新手,我坚持这个小问题它说解析错误我无法识别我的代码中缺少什么...... 提前感谢
public function home(){
echo'
<div style="color: #FFF; font-weight: 700; text-shadow: 1px 1px 4px rgba(0,0,0,0.6);overflow: hidden; background-size: 50%; background-color: rgba(0,0,0,0.8);background-image: url('public.jpg');" class="page-title"><div class="container clearfix"> <div class="sixteen columns"> <h1 style=" padding: 5px 10px; background: rgba(255,255,255,0.1); line-height: 75px; text-transform: uppercase; letter-spacing: 2px; font-family: 'Open Sans Condensed', sans-serif; font-weight: 300;"><br><center><b>Welcome To '.$_SERVER[HTTP_HOST].' BOT</b></center></h1><br><p style="
float: left;
font-size: 16px;
';
答案 0 :(得分:0)
你需要转义单引号:
public function home(){
echo'
<div style="color: #FFF; font-weight: 700; text-shadow: 1px 1px 4px rgba(0,0,0,0.6);overflow: hidden; background-size: 50%; background-color: rgba(0,0,0,0.8);background-image: url(\'public.jpg\');" class="page-title"><div class="container clearfix"> <div class="sixteen columns"> <h1 style=" padding: 5px 10px; background: rgba(255,255,255,0.1); line-height: 75px; text-transform: uppercase; letter-spacing: 2px; font-family: \'Open Sans Condensed\', sans-serif; font-weight: 300;"><br><center><b>Welcome To '.$_SERVER[HTTP_HOST].' BOT</b></center></h1><br><p style="
float: left;
font-size: 16px;
';
答案 1 :(得分:0)
您需要转义背景图片的单引号,因为您的字符串也使用单引号。
public function home(){
echo '<div style="color: #FFF; font-weight: 700; text-shadow: 1px 1px 4px rgba(0,0,0,0.6);overflow: hidden; background-size: 50%; background-color: rgba(0,0,0,0.8);background-image: url(\'public.jpg\');" class="page-title"><div class="container clearfix"> <div class="sixteen columns"> <h1 style=" padding: 5px 10px; background: rgba(255,255,255,0.1); line-height: 75px; text-transform: uppercase; letter-spacing: 2px; font-family: \'Open Sans Condensed\', sans-serif; font-weight: 300;"><br><center><b>Welcome To '.$_SERVER['HTTP_HOST'].' BOT</b></center></h1><br><p style="float: left;font-size: 16px;">....';
}
我建议你分开php,html和css。这种结构对可读性和可维护性非常不利。
简单示例:
function view($host)
{
return '<div id="foo">
<h1 class="title">Welcome to ' . $host . '</h1>
</div>';
}
echo view('my host');
答案 2 :(得分:0)
使用double quotes
代替single quote
。如果您将php
与HTML
分开,则不存在这些类型的问题。
<?php
public function home(){
echo'
<div style="color: #FFF; font-weight: 700;
text-shadow: 1px 1px 4px rgba(0,0,0,0.6);overflow: hidden;
background-size: 50%; background-color: rgba(0,0,0,0.8);
background-image: url("public.jpg");"
class="page-title"><div class="container clearfix"> <div class="sixteen columns">
<h1 style=" padding: 5px 10px; background: rgba(255,255,255,0.1);
line-height: 75px; text-transform: uppercase; letter-spacing: 2px;
font-family: "Open Sans Condensed", sans-serif; font-weight: 300;">
<br><center><b>Welcome To '.$_SERVER[HTTP_HOST].' BOT</b></center></h1>
<br><p style="
float: left;
font-size: 16px;';
}
?>