0
echo '<meta property="article:published_time" content="<?php echo htmlentities($datePublished, \ENT_QUOTES, "UTF-8", false); ?>">';

result: <meta property="article:published_time" content="<?php echo htmlentities($datePublished, \ENT_QUOTES, "UTF-8", false); ?>"> And i get "> printed above the navbar

I know that it's because of the double quotes that starts on content=", but i need to put the UTF-8 on the code line.

I cant put "" and i can't put '', so what i do? There's a way to echo this?

Natalie
  • 77
  • 10
  • using a \ before a " will cancel it out. And your already in PHP so no need for the – ATechGuy Oct 01 '18 at 22:27
  • Possible duplicate of [What is the difference between single-quoted and double-quoted strings in PHP?](https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – miken32 Oct 01 '18 at 22:56

1 Answers1

1

You could make use of backslashes (\) to escape your quotes, however, I would recommend separating this out into three 'conjoined' echo statements (separated with .); one for the start of the HTML <meta>, one for the htmlentities(), and one for the end of the <meta>:

echo '<meta property="article:published_time" content="' .
htmlentities($datePublished, \ENT_QUOTES, "UTF-8", false) . 
'">';

Or on one line:

echo '<meta property="article:published_time" content="' . htmlentities($datePublished, \ENT_QUOTES, "UTF-8", false) . '">';

This will output:

<meta property="article:published_time" content="SOME_DATE">
Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
  • I saw that your "Top tags" is html, i have one question, would be there a problem if i have a `meta tag` on this way `` together on the same line? – Natalie Oct 01 '18 at 22:40
  • The 'closing' component I was referring to was simply the `>` in ``. Having said that, it's absolutely fine to have `` on the same line; the `` tag is an [**empty (void element)**](https://developer.mozilla.org/en-US/docs/Glossary/Empty_element), so it essentially 'self-closes'. You won't have a problem in doing this... but it's generally 'nicer' to have them separated out onto new lines. Consider appending [**`PHP_EOL`**](http://php.net/manual/en/reserved.constants.php) to your `echo` statement :) – Obsidian Age Oct 01 '18 at 22:46