单引号代替双引号? [英] Single Quotes Instead of Double Quotes?

查看:148
本文介绍了单引号代替双引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于都是通过HTML以及像ASP.NET和PHP语言的使用接受属性或字符串时,为什么有些人用单引号和双引号互换?

这是我的理解是,语法正确,当你需要嵌入内联逻辑的双引号在可能情况下,单用双引号。

有我丢失的东西?

有关的例子:

HTML

 < A HREF =HTTP://google.com'>谷歌< / A>

PHP

 &LT ;?呼应的'Hello World!; ?>

ASP.NET

 <形式ID ='myForm的'RUNAT ='服务器'>< /表及GT;


解决方案

在HTML中,我不认为为什么可在任何东西,但明显的例子来回答:单引号字符串时更方便字符串包含双报价,反之亦然。

在PHP中,单引号字符串是当你不希望任何特殊的插值或转义字符更方便。

我个人的preference总是在HTML中使用双引号,并且始终使用单引号在PHP中,除非我需要插值。因此,我认为单引号的字符串是种在PHP中的常数,而双引号的字符串意味着别的东西是怎么回事。

<意见>可是为什么有些人古怪两者之间进行选择?大概是因为他们不守纪律​​,随后不是很好的程序员< /意见>

Since both are acceptable by HTML as well as languages like ASP.NET and PHP when using attributes or strings, why is it that some people use single quotes and double quotes interchangeably?

It is my understanding that it is syntactically correct to use double quotes where possible, single when you need to embed a double quote for inline logic.

Is there something I am missing?

For examples:

HTML

<a href='http://google.com'>Google</a>

PHP

<? echo 'Hello World!'; ?>

ASP.NET

<form id='myForm' runat='server'></form>

解决方案

In HTML, I don't think the "why" can be answered in anything but the obvious case: single quoted strings are more convenient when the string contains double quotes, and vice-versa.

In PHP, single quoted strings are more convenient when you don't want any special interpolation or escape characters.

My personal preference is always use double quotes in HTML, and to always use single quotes in PHP unless I need interpolation. Thus, I consider the single quoted strings to be "constants" of sorts in PHP, while the double quoted string implies something else is going on.

<opinion>But why do some people whimsically choose between the two? Probably because they are undisciplined and subsequently not very good programmers.</opinion>

这篇关于单引号代替双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆