0

I have a full HTML page:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>Template</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
  ...
</head>
<body>
...
</body>
</html>

I'm trying to save it in a variable like so:

$template = htmlentities("<!DOCTYPE HTML><html lang="en-US">...", ENT_HTML5, "UTF-8" );

.. but it chokes at just the first HTML tag.

eozzy
  • 66,048
  • 104
  • 272
  • 428
  • Err, use [heredoc](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc)? – Ja͢ck Feb 06 '15 at 06:48

5 Answers5

4

That's because the first HTML tag has double quotes, just like you use for delimiting your string literal.

$template = <<<EOD
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>Template</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
  ...
</head>
<body>
...
</body>
</html>
EOD;
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

You are not escaping the string propertly Try to: Replace

htmlentities("//whatever your html code is//");

with

htmlentities('//whatever your html code is//');
Nishanth Matha
  • 5,993
  • 2
  • 19
  • 28
0

user addslashes function..it will not truncate your string in between. This function can be used to prepare a string for storage in a database and database queries.

Before storing into database or for any purpose

$final_string = addslashes('<!DOCTYPE HTML>

..........');

Before rendering that output on browser

$normal_string = stripslashes($database_retrived_string);
Prashant M Bhavsar
  • 1,136
  • 9
  • 13
0

Try this:

$temp     = addslashes('<!DOCTYPE HTML><html lang="en-US">...', ENT_HTML5, "UTF-8" );

$template = htmlentities($temp);
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
0
$data = '<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>Template</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
  ...
</head>
<body>
...
</body>
</html>';

base64_encode($data);

Raj
  • 150
  • 1
  • 10
  • He would still have to manually escape all of the single quotes. Heredoc works. Not sure why he wouldn't just read the file in though... – Bitwise Creative Feb 06 '15 at 06:50