I'm using PHP code to generate my meta description tag, like so:
<meta name="description" content="<?php
echo $this->utf->clean_string(word_limiter(strip_tags(trim($paperResult['file_content'])),27));
?>
Here's an example of the meta description output:
<meta name="description" content="blah blah ¶ … blah blah "words in quotation marks" blah blah "more words in quotation marks" blah blah" />
The two HTML entities in that example meta description are a paragraph sign (¶
) followed by an ellipsis (…
). They are already in HTML entity form in the source text, so I want them to remain unchanged. The problem is that I also need the quotation marks within the description to convert to "
in order to prevent the meta tag from breaking. Every combination/configuration that I try either does not work or breaks my site because I'm getting the code wrong. For example, when I try the following code, the quotation marks convert to their HTML entity, as desired, but the paragraph symbol and ellipsis entities break because the ampersand character at the beginning of the existing HTML entities gets converted to &
. That leaves me with a broken ¶
(&#182;
) and a broken …
(&#8230;
) :
echo $this->utf->clean_string(word_limiter(htmlspecialchars(strip_tags(trim($paperResult['file_content']))),27));
I've been trying—literally, for days—to figure this out. I've searched extensively in Stack Overflow, to no avail. I just need the existing HTML entities to remain unchanged and quotation marks to be converted to their HTML entity ("
). I have studied the ENT_QUOTES option and I know that the solution probably exists therein, but I can't figure out how to incorporate it into my particular line of code. I'm hoping that you PHP gurus will have mercy on this tortured soul! I'd truly appreciate your help.
Thank you!