要使用PHP生成XML,可以使用以下代码:
<?php
// 创建一个XML文档
$xml = new DOMDocument("1.0", "UTF-8");
// 创建根元素
$root = $xml->createElement("root");
$xml->appendChild($root);
// 创建子元素
$child = $xml->createElement("child");
$root->appendChild($child);
// 创建元素属性
$attribute = $xml->createAttribute("attribute_name");
$attribute->value = "attribute_value";
$child->appendChild($attribute);
// 添加文本节点
$text = $xml->createTextNode("This is the content of the child element.");
$child->appendChild($text);
// 将XML保存到文件
$xml->save("output.xml");
?>
要使用PHP生成PDF,可以使用第三方库如FPDF或TCPDF。以下是使用FPDF生成PDF的示例:
<?php
require('fpdf.php');
// 创建PDF对象
$pdf = new FPDF();
// 添加页面
$pdf->AddPage();
// 设置字体和字号
$pdf->SetFont('Arial', 'B', 16);
// 添加文本
$pdf->Cell(40, 10, 'Hello World!');
// 输出PDF
$pdf->Output();
?>
请注意,这些只是生成XML和PDF的基本示例,你可以根据自己的需求进行修改和扩展。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站