YAML 데이터 직렬화 yaml_emit
(PECL yaml >= 0.5.0)
yaml_emit — 값의 YAML 표현을 반환합니다.
설명
yaml_emit( mixed $data, int $encoding = YAML_ANY_ENCODING, int $linebreak = YAML_ANY_BREAK, array $callbacks = null ): string
제공된 data
의 YAML 표현을 생성합니다.
매개변수
data
- 인코딩 중인
data
입니다. 리소스를 제외한 모든 유형이 될 수 있습니다. encoding
YAML_ANY_ENCODING
,YAML_UTF8_ENCODING
,YAML_UTF16LE_ENCODING
,YAML_UTF16BE_ENCODING
에서 선택한 출력 문자 인코딩.linebreak
YAML_ANY_BREAK
,YAML_CR_BREAK
,YAML_LN_BREAK
,YAML_CRLN_BREAK
에서 선택한 출력 줄 바꿈 스타일.callbacks
- YAML 노드를 내보내는 콘텐츠 핸들러. 클래스 이름의 연관 배열 => callable 매핑. 자세한 내용은 emit callbacks을 참조하세요.
반환 값
성공하면 YAML 인코딩된 문자열을 반환합니다.
변경 로그
버전 | 설명 |
---|---|
PECL yaml 1.1.0 | callbacks 매개 변수가 추가되었습니다. |
Examples
예제 #1 yaml_emit() 예제
<?php
$addr = array(
"given" => "Chris",
"family"=> "Dumars",
"address"=> array(
"lines"=> "458 Walkman Dr.
Suite #292",
"city"=> "Royal Oak",
"state"=> "MI",
"postal"=> 48046,
),
);
$invoice = array (
"invoice"=> 34843,
"date"=> 980208000,
"bill-to"=> $addr,
"ship-to"=> $addr,
"product"=> array(
array(
"sku"=> "BL394D",
"quantity"=> 4,
"description"=> "Basketball",
"price"=> 450,
),
array(
"sku"=> "BL4438H",
"quantity"=> 1,
"description"=> "Super Hoop",
"price"=> 2392,
),
),
"tax"=> 251.42,
"total"=> 4443.52,
"comments"=> "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.",
);
var_dump(yaml_emit($invoice));
?>
위의 예는 다음과 유사한 결과를 출력합니다.
string(628) "--- invoice: 34843 date: 980208000 bill-to: given: Chris family: Dumars address: lines: |- 458 Walkman Dr. Suite #292 city: Royal Oak state: MI postal: 48046 ship-to: given: Chris family: Dumars address: lines: |- 458 Walkman Dr. Suite #292 city: Royal Oak state: MI postal: 48046 product: - sku: BL394D quantity: 4 description: Basketball price: 450 - sku: BL4438H quantity: 1 description: Super Hoop price: 2392 tax: 251.420000 total: 4443.520000 comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. ... "
기타
- yaml_emit_file() - 값의 YAML 표현을 파일로 보내기
- yaml_parse() - YAML 스트림 구문 분석