development

HTML에서 작은 따옴표를 사용할 수 있습니까?

big-blog 2020. 6. 23. 21:41
반응형

HTML에서 작은 따옴표를 사용할 수 있습니까?


PHP에서 큰 따옴표를 사용하여 문자열을 연결하는 대신 변수를 보간 할 수있는 좋은 시간입니다. 결과적으로 HTML을 생성 할 때 종종 태그 필드를 설정하기 위해 작은 따옴표를 사용합니다. 예를 들면 다음과 같습니다.

$html = "<input type='text' name='address' value='$address'>";

이제 이것은 어느 것보다 훨씬 읽기 쉽습니다.

$html = "<input type=\"text\" name=\"address\" value=\"$address\">";

또는

$html = '<input type="text" name="address" values="' . $address . '">' ;

간단한 검색에서 HTML 필드에 대한 작은 따옴표는 모든 브라우저에서 인식되지 않는다는 사람들의 말을 들었습니다. 따라서 작은 따옴표 HTML을 인식하는 데 어떤 브라우저가 문제가 될지 궁금합니다.


이것은 HTML에서 작은 따옴표언제 대중화 되었는가 와 비슷합니다 . . HTML의 속성에 대한 작은 따옴표 는 사양에서 항상 허용됩니다 . 나는 어떤 브라우저도 이해할 수 없다고 생각합니다.


PhiLho가 지적한 바와 같이, 속성 값에 작은 따옴표가 허용되지 않는다는 믿음이 널리 퍼져 있지만 그 믿음은 잘못되었습니다.

XML 표준은 속성 값의 주위에 모두 단일 및 이중 따옴표를 허용합니다.

XHTML 표준은 이것을 변경하기 위해 아무 말도하지 않지만 속성 값을 인용해야 한다는 관련 섹션 은 예제에서 큰 따옴표를 사용하므로 혼란을 초래할 수 있습니다. 이 예제는 XHTML의 속성 값이 XML의 속성 값에 대한 최소 표준을 충족해야한다는 것을 지적합니다. 즉, 중요하지 않은 일반 HTML과 달리 따옴표로 묶어야하지만 단일 또는 큰 따옴표.

물론 표준을 준수하지 않는 파서가 발생할 가능성은 항상 있지만, 그렇게되면 모든 베팅이 중단됩니다. 따라서 사양에 명시된 내용 만 준수하는 것이 가장 좋습니다. 결국 우리는 사양을 갖습니다.


사람들이 HTML 필드에 대한 작은 따옴표를 모든 브라우저에서 인식하지 못한다고 말하는 것을 들었습니다.

그 사람이 틀렸다


인터넷에서 보는 모든 것을 믿지 마라 ...
재미있게, 나는 작은 따옴표가 XHTML에서 유효하지 않다고 선언하는 누군가와 비슷한 것을 대답했다 ...

음, 입력하는 동안 위를보고 Adam N이 같은 믿음을 전파한다는 것을 알 수 있습니다. 그가 확인을 뒷받침 할 수 있다면, 내가 쓴 것을 철회합니다. AFAIK, XML은 불가지론 적이며 두 종류의 인용을 모두 받아들입니다. 심지어 작은 따옴표 만있는 XHTML 페이지를 문제없이 시도하고 검증했습니다.


문제는 텍스트 입력 필드로 들어가는 데이터입니다. 치다

<input value='it's gonna break'/>

와 같다:

<input value="i say - "this is gonna be trouble" "/>

당신은 그것을 벗어날 수 없습니다, 당신은 사용해야 htmlspecialchars합니다.


또한 HTML에서 작은 따옴표를 사용하는 경향이 있으며 문제가 발생하지 않았습니다.


HTML 페이지에서 작은 따옴표를 사용하고 JavaScript를 포함 시켰으며 정상적으로 작동합니다. IE9, Chrome 및 Firefox에서 테스트되었습니다. 작동하는 것 같습니다.

<!DOCTYPE html>
<html>
    <head>
        <meta charset='utf-8'>
        <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
        <title>Bethanie Inc. data : geographically linked</title>
        <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>
        <script src='https://maps.googleapis.com/maps/api/js?v=3.11&sensor=false' type='text/javascript'></script>
        <script type='text/javascript'> 
        // check DOM Ready
        $(document).ready(function() {
            // execute
            (function() {
                /////////////// Addresses ///////////////////
                var locations = new Array();
                var i = 0;
                locations[i++] = 'L,Riversea: Comp Site1 at Riversea,1 Wallace Lane Mosman Park WA 6012'
                locations[i++] = 'L,Wearne: Comp Site2 at Wearne,1 Gibney St Cottesloe WA 6011'
                locations[i++] = 'L,Beachside:Comp Site3 Beachside,629 Two Rocks Rd Yanchep WA 6035'

                /////// Addresses/////////
                var total_locations = i;
                i = 0;
                console.log('About to look up ' + total_locations + ' locations');
                // map options
                var options = {
                    zoom: 10,
                    center: new google.maps.LatLng(-31.982484, 115.789329),//Bethanie  
                    mapTypeId: google.maps.MapTypeId.ROADMAP,
                    mapTypeControl: true
                };
                // init map
                console.log('Initialise map...');
                var map = new google.maps.Map(document.getElementById('map_canvas'), options);
               // use the Google API to translate addresses to GPS coordinates 
               //(See Limits: https://developers.google.com/maps/documentation/geocoding/#Limits)
                var geocoder = new google.maps.Geocoder();
                if (geocoder) {
                    console.log('Got a new instance of Google Geocoder object');
                    // Call function 'createNextMarker' every second
                    var myVar = window.setInterval(function(){createNextMarker()}, 700);
                    function createNextMarker() {
                        if (i < locations.length) 
                       {
                            var customer = locations[i];
                            var parts = customer.split(','); // split line into parts (fields)
                            var type= parts.splice(0,1);    // type from location line (remove)
                            var name = parts.splice(0,1);    // name from location line(remove)
                            var address =parts.join(',');   // combine remaining parts
                            console.log('Looking up ' + name + ' at address ' + address);
                            geocoder.geocode({ 'address': address }, makeCallback(name, type));
                            i++; // next location in list
                            updateProgressBar(i / total_locations);


                        } else 
                       {
                            console.log('Ready looking up ' + i + ' addresses');
                            window.clearInterval(myVar);
                        }
                    }

                    function makeCallback(name,type) 
                   {
                        var geocodeCallBack = function (results, status) {
                            if (status == google.maps.GeocoderStatus.OK) {
                                var longitude = results[0].geometry.location.lng();
                                var latitude = results[0].geometry.location.lat();
                                console.log('Received result: lat:' + latitude + ' long:' + longitude);
                                var marker = new google.maps.Marker({
                                    position: new google.maps.LatLng(latitude, longitude),
                                    map: map,
                                    title: name + ' : ' + '\r\n' + results[0].formatted_address});// this is display in tool tip/ icon color
                                   if (type=='E')  {marker.setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png')};

더 최신 버전의 사양 에서 이것에 대한 정보를 찾고 있었고 그것을 찾는 데 꽤 시간이 걸렸습니다.

에서

HTML 5.3

편집자 초안, 2018 년 10 월 18 일

[...]

8.1.2.3. 속성

작은 따옴표로 묶은 속성 값 구문

The attribute name, followed by zero or more space characters, followed by a single U+003D EQUALS SIGN character, followed by zero or more space characters, followed by a single U+0027 APOSTROPHE character ('), followed by the attribute value, which, in addition to the requirements given above for attribute values, must not contain any literal U+0027 APOSTROPHE characters ('), and finally followed by a second single U+0027 APOSTROPHE character (').

In the following example, the type attribute is given with the single-quoted attribute value syntax:

<input type='checkbox'>

If an attribute using the single-quoted attribute syntax is to be followed by another attribute, then there must be a space character separating the two.

http://w3c.github.io/html/single-page.html#elements-attributes


Recently i've experienced a problem with Google Search optimization. If has a single quotes, it doesn't seem to crawl linked pages.


... or just use heredocs. Then you don't need to worry about escaping anything but END.


Single Quotes are fine for HTML, but they don't make valid XHTML, which might be problematic if anybody was using a browser which supported only XHTML, but not HTML. I don't believe any such browsers exist, though there are probably some User-Agents out there that do require strict XHTML.

참고URL : https://stackoverflow.com/questions/273354/are-single-quotes-allowed-in-html

반응형