Jump to content


Photo

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


  • Please log in to reply
7 replies to this topic

#1 operafanboy

operafanboy
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 18 March 2006 - 08:08 AM

If so what would be an example? I'm just curious.

Cheers

#2 v-wdd

v-wdd
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • Location127.0.0.1

Posted 18 March 2006 - 06:29 PM

You mean using "&" instead of "&"...
If yes, then it is necessary, for XHTML validation.

#3 operafanboy

operafanboy
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 19 March 2006 - 04:04 AM

[!--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) View Post[/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.

#4 azziman

azziman
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 20 March 2006 - 03:41 PM

[!--quoteo(post=356333:date=Mar 19 2006, 04:04 AM:name=operafanboy)--][div class=\'quotetop\']QUOTE(operafanboy @ Mar 19 2006, 04:04 AM) View Post[/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 ;)


#5 rawb

rawb
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 21 March 2006 - 01:13 PM

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!

#6 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 23 March 2006 - 10:58 AM

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.c...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.
OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#7 gnuffo1

gnuffo1
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 24 March 2006 - 10:53 PM

I don't know if & works in JS, but &038; definitly does and my page validates with it.
[a href="http://www.sentinelpc.co.uk" target="_blank"]Sentinel Technology - Custom PCs and Laptops[/a]

#8 charlesfw

charlesfw
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 16 April 2006 - 11:32 PM

[!--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) View Post[/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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users