Separate quotes instead of double quotes?

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

I understand that it is syntactically correct to use double quotes, wherever possible, single quotes when you need to embed a double quote for inline logic.

Is there something I am missing?

Examples:

HTML

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

Php

<? echo 'Hello World!'; ?>

ASP.NET

<form id='myForm' runat='server'></form>
+3
source share
7 answers

In HTML, I don’t think that the β€œwhy” can be answered with anything but the obvious: single quotes are more convenient when a string contains double quotes and vice versa.

PHP , escape-.

HTML PHP, . , , "" PHP, , - .

< > ? , , . </opinion>

+1

W3C: http://www.w3.org/TR/html4/intro/sgmltut.html

All attribute values [should] be delimited using either double quotation
marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39).

Single quote marks can be included within the attribute value when the
value is delimited by double quote marks, and vice versa.

PHP - / .

0

, .

/ .

'Hello'

"Hello"

.

. , . .

. , , . , , , .. .

0

, . .

0

, , html , . :

public string EmailTemplate = 
@"<div style='color:red'>HEY {0}! BUY MORE STUFF</div>"

// later in code

instanceOfStringBuilder.AppendFormat(EmailTemplate, firstNameVariable); 

- , "". , -, .

0

@stullstanding HTML. , PHP , . :

<?php
    $id = 123;
    echo "Your id is $id<br />";
    echo 'Your id is $id';
?>

123

$id

0

Source: https://habr.com/ru/post/1777758/


All Articles