どうすればxmlの子にcdataを追加できますか?私はこのコードを手に入れました:
$errors = array();
if(isset($_POST['newtopic'])){
$topicname = preg_replace('/[^A-Za-z]/', '', $_POST['topicname']);
$textarea = $_POST['textarea'];
$desc = $_POST['desc'];
$startedby = $_POST['startedby'];
$tn = $_POST['topicname'];
if($topicname == ''){
$errors[] = 'You`re topic title is missing!';
}
if($topicname == ''){
$errors[] = 'You`re textarea is missing!';
}
if(count($errors) == 0){
$xml = new SimpleXMLElement('<topic></topic>');
$xml->addChild('textarea', $textarea);
$xml->addChild('desc', $desc);
$xml->addChild('startedby', $startedby);
$xml->addChild('date', $date);
$xml->addChild('topicname', $tn);
$xml->asXML('topics/sitenews/' . $topicname . '.xml');
header('Location: sitenews.php');
die;
}
}
cdataを$textarea部分にのみ追加したいのですが、すでに使用してみ'<![CDATA['. $textarea .']]>'
ましたが、機能しません。
前もって感謝します。