라이브러리
[PHP] DomHTMLDocument::saveHtml - 문서를 HTML 문자열로 직렬화합니다.
PHP의 DomHTMLDocument::saveHtml
PHP의 DomHTMLDocument::saveHtml 메소드는 HTML 문서를 문자열로 반환하는 메소드입니다. 이 메소드는 HTML 문서를 파싱하고, 파싱된 HTML 문서를 문자열로 반환합니다.
# 사용법
#hostingforum.kr
php
$html = new DOMDocument();
$html->loadHTML('
Hello, World!');
echo $html->saveHTML();
# 예제
#hostingforum.kr
php
$html = new DOMDocument();
$html->loadHTML('
Hello, World!');
echo $html->saveHTML(); //
Hello, World!
$html = new DOMDocument();
$html->loadHTML('
Hello, World!');
echo $html->saveHTML(); //
Hello, World!
$html = new DOMDocument();
$html->loadHTML('
Hello, World!');
$html->formatOutput = true;
echo $html->saveHTML(); //
Hello, World!
# 옵션
DomHTMLDocument::saveHTML 메소드는 다음과 같은 옵션을 제공합니다.
- `formatOutput` : HTML 문서를 문자열로 반환할 때, HTML 문서의 포맷을 유지하는지 여부를 결정합니다. 기본값은 false입니다.
#hostingforum.kr
php
$html = new DOMDocument();
$html->loadHTML('
Hello, World!');
$html->formatOutput = true;
echo $html->saveHTML(); //
Hello, World!
# 주의
DomHTMLDocument::saveHTML 메소드는 HTML 문서를 파싱하고, 파싱된 HTML 문서를 문자열로 반환합니다. 이 메소드는 HTML 문서의 구조를 변경하지 않습니다. 그러나 HTML 문서의 내용을 변경할 수 있습니다.
#hostingforum.kr
php
$html = new DOMDocument();
$html->loadHTML('
Hello, World!');
$html->getElementsByTagName('p')->item(0)->nodeValue = 'Hello, Universe!';
echo $html->saveHTML(); //
Hello, Universe!
# 결론
DomHTMLDocument::saveHTML 메소드는 HTML 문서를 문자열로 반환하는 메소드입니다. 이 메소드는 HTML 문서를 파싱하고, 파싱된 HTML 문서를 문자열로 반환합니다. 이 메소드는 HTML 문서의 구조를 변경하지 않지만, HTML 문서의 내용을 변경할 수 있습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.