채택완료

echo 내에 따옴표 처리에 관하여

2022-03-06 (일) 18:09:12 2,046
Copy
echo "<input class='button2' type='button' value='확인' onclick='document.location.href='./p.php'' />";

기초가 없다보니 이런데서 헤매네요.

위 코드에서 onclick='document.location.href='./p.php''  이부분 따옴표를 어떻게 처리해야하는지 궁굼합니다.

|

답변 3개 / 댓글 3개

채택된 답변
+20 포인트

echo "<input class='button2' type='button' value='확인' onclick=\"document.location.href='./p.php' \" />";

이렇게 해보세요

답변에 대한 댓글 1개

2022-03-06 (일) 19:15:05
답변 감사합니다.
2022-03-06 (일) 19:36:33

+ echo

- https://www.php.net/manual/en/function.echo

- https://www.php.net/manual/en/language.types.string.php

- https://www.php.net/manual/en/language.types.array.php

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

"로 감싼 안쪽에 " 표시는 \" ... echo "this is \"test\" string - 'ok'";

'로 감싼 안쪽에 ' 표시는 \' ... echo 'this is \'test\' string - "ok"';

Copy
echo "<input class=\"button2\" type=\"button\" value=\"확인\" onclick=\"document.location.href='./p.php'\" />";
echo '<input class="button2" type="button" value="확인" onclick="document.location.href=\'./p.php\'" />';

답변에 대한 댓글 1개

생략 가능하지만 비추천입니다.

- https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/HTML_basics
- https://developer.mozilla.org/ko/docs/Learn/Getting_started_with_the_web/HTML_basics

3. The attribute value wrapped by opening and closing quotation marks.
3. 속성 값의 앞 뒤에 열고 닫는 인용부호(" 또는 ')가 있어야 합니다. [그냥 한글 페이지 그대로 복사]

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

참고로 남긴 댓글인데 그렇게 느꼈다면 죄송합니다.
가급적 규칙 지켰으면 하는 바람으로 Reference Manual의 링크 남기곤 하는데
이젠 그만두도록 해야겠네요.
2022-03-06 (일) 19:06:19

onclick=location.href='./p.php'

따옴표 없이 이렇게만 써도 됩니다.

답변에 대한 댓글 1개

2022-03-06 (일) 19:14:56
헐... 따옴표 없어도 됐군요.. ㅜㅜ;
채택이 하나라 죄송합니다.

답변을 작성하려면 로그인이 필요합니다.