douxian6086 2010-09-29 08:19
浏览 22
已采纳

搜索引擎和'&'字符

I am about to finish up my dynamic classifieds website (php) and have some problem with figuring out how to write the meta and title tags.

I have read mixed articles about the & sign, and how to use it in the title or meta tags properly.

What role does the document encoding have and does the DOCTYPE have anything to do with this also?

In my case, this is my document top:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

I wonder, should I write the and tags with an '&' or an '&amp;' instead?

Just as an example:

 <title>Dolce & Gabbana</title>
             or
 <title>Dolce &amp; Gabbana</title>

I can't use the word 'and' simply because it doesn't "look" as good.

Thanks

  • 写回答

4条回答 默认 最新

  • dongxuxian6930 2010-09-29 08:37
    关注

    In this case both &amp; and even just & are valid as the latter is followed by a whitespace and thus cannot be confused with a reference open delimiter.

    But the HTML 4 specification recommends to use &amp; to avoid ambiguity:

    Authors should use "&amp;" (ASCII decimal 38) instead of "&" to avoid confusion with the beginning of a character reference (entity reference open delimiter). Authors should also use "&amp;" in attribute values since character references are allowed within CDATA attribute values.

    See my answer on Do I really need to encode '&' as '&amp;'? for further information.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?