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...
<div class='tcell5'>
<span>
<img src='/images/editors_choice_25x11.png' alt='Editors Choice' title='Editors Choice' />
</span>
</div>";
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…
Editor’s Choice
Sincerely,
Debbie
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?
Sincerely,
Debbie
DoubleDee:
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?
Sincerely,
Debbie
Nope - same reply. That’s the HTML escape character for the single quote.
:tup:
I just never stop learning things around here!
Thanks!
Debbie
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.
Thanks,
Debbie
Yet another alternative especially since you are using PHP variables:)
Try this:
<?php
$apostrophe = "Editor's choice";
echo '
<q>Mixing Single and Double Quotes - BEWARE: must start with a SINGLE quote</q>
<div class="tcell5">
<span>
<img src="/images/editors_choice_25x11.png" alt="' .$apostrophe .'" title="' .$apostrophe .'" />
</span>
</div>
<br /><br />
';
$link = <<< DEBBIE
<q>Using HEREDOC - BEWARE: $apostrophe must be enclosed in "DOUBLE" quotes</q>
<div class="tcell5">
<span>
<img src='/images/editors_choice_25x11.png' alt="$apostrophe" title="$apostrophe" />
</span>
</div>
DEBBIE;
echo $link;
?>
PHP HEREDOC has very strict syntax rules:
Absolutely no characters after the initial declaration, not even a single space
Absolutely no characters after the final ; not even a single space
Sincerely,
John_Betong