DOMDocument::createComment

(PHP 5, PHP 7, PHP 8)

DOMDocument::createComment โ€” ๆ–ฐใ—ใ„ comment ใƒŽใƒผใƒ‰ใ‚’ไฝœๆˆใ™ใ‚‹

่ชฌๆ˜Ž

public function DOMDocument::createComment(string $data): DOMComment

ใ“ใฎ้–ขๆ•ฐใฏใ€DOMComment ใ‚ฏใƒฉใ‚นใฎๆ–ฐใ—ใ„ใ‚คใƒณใ‚นใ‚ฟใƒณใ‚นใ‚’ไฝœๆˆใ—ใพใ™ใ€‚ใ“ใฎใƒŽใƒผใƒ‰ใฏใ€( DOMNode::appendChild() ใชใฉใง) ๆŒฟๅ…ฅใ•ใ‚Œใชใ„้™ใ‚Šใ€ใƒ‰ใ‚ญใƒฅใƒกใƒณใƒˆๅ†…ใซใ‚ใ‚‰ใ‚ใ‚Œใพใ›ใ‚“ใ€‚

ใƒ‘ใƒฉใƒกใƒผใ‚ฟ

data

ใ‚ณใƒกใƒณใƒˆใฎๅ†…ๅฎนใ€‚

ๆˆปใ‚Šๅ€ค

ๆ–ฐใ—ใ„ DOMComment ใ‚’่ฟ”ใ—ใพใ™ใ€‚

ๅค‰ๆ›ดๅฑฅๆญด

ใƒใƒผใ‚ธใƒงใƒณ ่ชฌๆ˜Ž
8.1.0 ใ‚จใƒฉใƒผใŒ็™บ็”Ÿใ—ใŸๅ ดๅˆใซใ€ DomException ใ‚’ใ‚นใƒญใƒผใ™ใ‚‹ใ‚ˆใ†ใซใชใ‚Šใพใ—ใŸใ€‚ ใ“ใ‚Œใ‚ˆใ‚Šๅ‰ใฎใƒใƒผใ‚ธใƒงใƒณใงใฏใ€false ใ‚’่ฟ”ใ—ใฆใ„ใพใ—ใŸใ€‚

ๅ‚่€ƒ

๏ผ‹add a note

User Contributed Notes 1 note

up
0
php dot sirlancelot at spamgourmet dot com ยถ
16 years ago
To prevent a parser error when the comment string would contain the character sequence "--", do this:

<?php

$CommentString = 'This contains -- some weird -- characters.';

$CommentNode = $DomDocument->createComment(
        str_replace('--', '-'.chr(194).chr(173).'-', $CommentString)
);
?>

This will insert a Soft Hyphen in between the two hyphens which will not cause the parser to error out.