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...
using & # 146; (minus the spaces) should work
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?
Nope - same reply. That's the HTML escape character for the single quote.
I just never stop learning things around here!
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.
Good point, but my actual code does contain PHP variables, so that wouldn't work in this case.
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
This topic is now closed. New replies are no longer allowed.