Jump to content

Is it ever necessary to use the ampersand escape character for html?


operafanboy

Recommended Posts

[!--quoteo(post=356209:date=Mar 18 2006, 01:29 PM:name=vic-wdd)--][div class=\'quotetop\']QUOTE(vic-wdd @ Mar 18 2006, 01:29 PM) [snapback]356209[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You mean using "&" instead of "&"...
If yes, then it is necessary, for XHTML validation.
[/quote]

Yeah, thanks. Is there any point to it though? I don't think I've ever needed to use it, and can't think of any time it would be needed, and it's pretty annoying having to remember to do it just so your page is valid.
Link to comment
Share on other sites

[!--quoteo(post=356333:date=Mar 19 2006, 04:04 AM:name=operafanboy)--][div class=\'quotetop\']QUOTE(operafanboy @ Mar 19 2006, 04:04 AM) [snapback]356333[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Yeah, thanks. Is there any point to it though? I don't think I've ever needed to use it, and can't think of any time it would be needed, and it's pretty annoying having to remember to do it just so your page is valid.
[/quote]

well if u type your text into dreamweaver (or u just copy it in) the "&" code will be there for u ;)
Link to comment
Share on other sites

I'm not sure if this is what you mean, but the ampersand is used to begin "special characters" in HTML. For example - if you ever need to know how to display a copyright ©, the HTML code is & #169; - but without the space in between the ampersand and the pound sign.

If this isn't what you mean, I'm dumb - sorry. If it is, hope I helped a bit!
Link to comment
Share on other sites

Like vic-wdd said, you need to use & in the code instead of & for it to be valid XHTML. Also, if you are writing in JavaScript that directs to a URL like "http://www.example.com/page.php?act=test&something=this", for example you cannot use the & in the JS code, it won't work, so you must use a normal ampersand even if it won't validate.
Link to comment
Share on other sites

  • 4 weeks later...
[!--quoteo(post=356209:date=Mar 18 2006, 02:29 PM:name=vic-wdd)--][div class=\'quotetop\']QUOTE(vic-wdd @ Mar 18 2006, 02:29 PM) [snapback]356209[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You mean using "&" instead of "&"...
If yes, then it is necessary, for XHTML validation.
[/quote]

I have a twist on this question. I have images stored in the database and to print them as a link, I must send all information relative to the <img> tag as an argument.

I don't want to distract from the issue, but this is the code that prepares the link to see a full-sized image from a thumbnail:

// Build full-size image link
$image_link = "print_full_image.php?";
$image_link .= "id=".$id;
$title = ereg_replace(" ", "%20", $title);
$image_link .= "&title=".$title;
$image_link .= "&seq=".$row->sequence;
$caption = ereg_replace(" ", "%20", $row->caption);
$image_link .= "&caption=".$caption;
$image_link .= "&table=$db_table";

// Build thumbnail image request
$image = "print_image.php?";
$image .= "id=".$id;
$image .= "&seq=".$row->sequence;
$image .= "&thumbnail=Y";
$image .= "&table=$db_table";

// Print link & image
print "<td><a href=".$image_link."><img src=".$image.
" alt=\"Click to see larger view\"/></a></td>";

It replace spaces with '%20' which appears to be what the browser (IE) does automatically. I don't know of any HTML or PHP method to do this automatically so I am building this string manually.

The issue is that if $caption contains an ampersand, it causes the rest of the text to be truncated. So it appears that '&' is illegal in this case since it is always interpreted as a separator.

Am I missing something?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.