-1

Hey friends I am new in php and I stuck in this small problem it says parse error I am not able to identify that what is missing in my this code......thanks in advance


PHP Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting ',' or ';' in /home/flexytk1/public_html/bot/index.php on line
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 Answers3

0

You need to escape single quotes:

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;
';
Angad Dubey
  • 5,067
  • 7
  • 30
  • 51
  • Thanks a lot I learn about this but currently I forget about it....thanks thanks a lot....and sorry for this easy question – Nalin Nishant May 18 '17 at 11:17
0

You need to escape your single quotes for back-ground-image, because your string uses single quotes too.

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;">....';
}

Recommendation

I recommend you to separate php, html and css. This structure is very bad for readability and maintainability.

  • Move your css code to a separate file
  • Move your html code to a function with arguments, simply like so:

Simple example:

function view($host)
{
    return '<div id="foo">
        <h1 class="title">Welcome to ' . $host . '</h1>
    </div>';
}

echo view('my host'); 
schellingerht
  • 5,726
  • 2
  • 28
  • 56
0

Use double quotes instead of single quote. if your separate your php from HTML, then these types of problem not there.

 <?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;';
}
?>
Hamza Zafeer
  • 2,360
  • 13
  • 30
  • 42