0

So I have this 30 lines long HTML code. I don't want to change all this " to \" I've created a php class called page and save in .inc file.

I have to assign these HTML code to $home->content. Is there anyway I can just copy and paste my html code to it?

This is how the page displays:

public function Display()
{
    echo "<html>\n<head>\n";
    $this -> DisplayTitle();
    $this -> DisplayKeywords();
    echo "</head>\n<body>\n";
    echo "<div class = \"container\">\n";
    $this -> DisplayHeader();
    echo $this -> content;
    $this -> DisplayFooter();
    echo "</div>\n</body>\n</html>\n";
}

Thank you in advance

Josh Mayer
  • 81
  • 4

2 Answers2

1

if you HTML code has all " in it then you can use single quote ' in the start and at the end of the echo statement and you do not need to change anything.

public function Display()
{
    echo '<html>\n<head>\n';
    $this -> DisplayTitle();
    $this -> DisplayKeywords();
    echo '</head>\n<body>\n';
    echo '<div class = "container">\n';
    $this -> DisplayHeader();
    echo $this -> content;
    $this -> DisplayFooter();
    echo '</div>\n</body>\n</html>\n';
}
Usman Khawaja
  • 809
  • 14
  • 28
1

While Usman's answer seems to have solved your problem, it might be useful to understand some of the differences between the different styles of quotes in PHP. This answer explains them in detail. One of the differences between single and double quotes is that double quotes will evaluate the string and any variables you place within will have their value(s) placed in your string.

For example:

$myNum = 2;
echo 'I have $myNum apples.'; //will output: I have $myNum apples.
echo "I have $myNum apples."; //will output: I have 2 apples.

This is obviously a very basic explanation of the differences.

Community
  • 1
  • 1
muttley91
  • 12,278
  • 33
  • 106
  • 160