错误500解析错误缺少某些内容

时间:2017-05-18 11:12:19

标签: php

嘿朋友我是php的新手,我坚持这个小问题它说解析错误我无法识别我的代码中缺少什么...... 提前感谢


PHP解析错误:语法错误,意外“公共”(T_PUBLIC),期待','或';'在/home/flexytk1/public_html/bot/index.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;
';

3 个答案:

答案 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。这种结构对可读性和可维护性非常不利。

  • 将您的css代码移至单独的文件
  • 将您的html代码移动到带参数的函数,就像这样:

简单示例:

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。如果您将phpHTML分开,则不存在这些类型的问题。

 <?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;';
}
?>