Tidy tidy::parseString

tidy_parse_string

(PHP 5, PHP 7, PHP 8, PECL tidy >= 0.5.2)

tidy::parseString -- tidy_parse_string — 문자열에 저장된 문서 구문 분석


설명

객체 지향 스타일

public tidy::parseString(string $string, array|string|null $config = null, ?string $encoding = null): bool

절차적 스타일

tidy_parse_string(string $string, array|string|null $config = null, ?string $encoding = null): tidy|false

문자열에 저장된 문서를 구문 분석합니다.


매개변수

string
구문 분석할 데이터입니다.
config
구성 config은 배열이나 문자열로 전달할 수 있습니다. 문자열이 전달되면 구성 파일의 이름으로 해석되고, 그렇지 않으면 옵션 자체로 해석됩니다.

각 옵션에 대한 설명은 » http://api.html-tidy.org/#quick-reference를 방문하세요.

encoding
encoding 매개변수는 입/출력 문서의 인코딩을 설정합니다. 인코딩에 가능한 값은 ascii, latin0, latin1, raw, utf8, iso2022, mac, win1252, ibm858, utf16, utf16le, utf16be, big5shiftjis입니다.

반환 값

tidy::parseFile()은 성공 시 true를 반환합니다. tidy_parse_file()은 성공 시 새로운 tidy 인스턴스를 반환합니다. 메서드와 함수 모두 실패 시 false를 반환합니다.


변경 로그

버전 설명
8.0.0 configencoding은 이제 nullable입니다.

Examples

예제 #1 tidy::parseString() 예제

                  
<?php
ob_start();
?>

<html>
  <head>
   <title>test</title>
  </head>
  <body>
   <p>error<br>another line</i>
  </body>
</html>

<?php

$buffer = ob_get_clean();
$config = array('indent' => TRUE,
                'output-xhtml' => TRUE,
                'wrap' => 200);

$tidy = tidy_parse_string($buffer, $config, 'UTF8');

$tidy->cleanRepair();
echo $tidy;
?>
                  
                

위의 예는 다음을 출력합니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>
      test
    </title>
  </head>
  <body>
    <p>
      error<br />
      another line
    </p>
  </body>
</html>
                

기타