doubledee — 2014-08-20T14:19:23-04:00 — #1
I am using PHP to echo some HTML, and the HTML is enclosed by double-quotes.
Is there a way to put an apostrophe in the TITLE attribute?
The problem is that my code looks like this...
echo " HTML starts here...
<img src='/images/editors_choice_25x11.png' alt='Editors Choice' title='Editors Choice' />
As you can see, the ALT and TITLE attributes are using Single-Quotes, so if I add another one it messes things up.
When a user hovers over my <span>, I want this to appear...
davemaxwell — 2014-08-20T14:21:53-04:00 — #2
using & # 146; (minus the spaces) should work
doubledee — 2014-08-20T14:25:34-04:00 — #3
David, you might want to re-read my OP. (I made some edits that might change your response.)
@ Mods: Maybe this should be moved to the PHP forum?
davemaxwell — 2014-08-20T14:45:17-04:00 — #4
Nope - same reply. That's the HTML escape character for the single quote.
doubledee — 2014-08-20T14:59:53-04:00 — #5
I just never stop learning things around here!
felgall — 2014-08-20T15:38:49-04:00 — #6
Since your code does not contain any PHP variables it would be more efficient to put single quotes around the whole thing and use double quotes for the HTML attributes. That way PHP will not search for variables in the string.
doubledee — 2014-08-20T15:58:29-04:00 — #7
Good point, but my actual code does contain PHP variables, so that wouldn't work in this case.
john_betong — 2014-08-20T23:15:53-04:00 — #8
Yet another alternative especially since you are using PHP variables:)
$apostrophe = "Editor's choice";
<q>Mixing Single and Double Quotes - BEWARE: must start with a SINGLE quote</q>
<img src="/images/editors_choice_25x11.png" alt="' .$apostrophe .'" title="' .$apostrophe .'" />
<br /><br />
$link = <<< DEBBIE
<q>Using HEREDOC - BEWARE: $apostrophe must be enclosed in "DOUBLE" quotes</q>
<img src='/images/editors_choice_25x11.png' alt="$apostrophe" title="$apostrophe" />
PHP HEREDOC has very strict syntax rules:
1. Absolutely no characters after the initial declaration, not even a single space
2. Absolutely no characters after the final ; not even a single space