加载 PHPExcel
L::open('excel') 详细 v1.8.0
<?php
L::open('excel'); //开启 excel
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0) //第一行数据
->setCellValue('A1', '中文标题')
->setCellValue('B1', 'éàèùâêîôûëïüÿäöüç')
->setCellValue('C1', 'Hello');
$objPHPExcel->setActiveSheetIndex(0) //第二行数据
->setCellValue('A2', 'valldonzella 48 3º 2ª')
->setCellValue('B2', 'world!')
->setCellValue('C2', 'Hello');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="test.xls"');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); //xls 标准
$objWriter->save('php://output'); //下载
?>
加载 PHPWord
L::open('word') 详细 v0.8.1
<?php
L::open('word');
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$section->addTitle('Welcome to PHPWord', 1);
$section->addText('Hello World!');
$section->addLink('http://www.google.com', null, 'NLink'); //创建连接
$section->addTextBreak();
header('Content-Type: application/vnd.ms-word');
header('Content-Disposition: attachment;filename="test.docx"');
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('php://output');
?>
加载 nuSoap(webService)
L::open('soap') 详细 v0.9.5
<?php
$client = new soapclient ('http://localhost/nusoapService.php');
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;
$client->xml_encoding = 'UTF-8';
$paras = array ('name' => 'Bruce Lee' ); //参数转为数组形式传递
$result = $client->call ( 'GetTestStr', $paras ); //目标方法没有参数时,可省略后面的参数
if( !$err = $client->getError () ) { //检查错误,获取返回值
echo " 返回结果: ", $result;
} else {
echo " 调用出错: ", $err;
}
?>
加载 phpMailer
L::open('mail') 详细 v5.2.13
<?php
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; //显示详细信息
$mail->isSMTP(); //设置 SMTP 模式
$mail->Host = 'smtp.qq.com'; //SMTP 服务器
$mail->SMTPAuth = true; //启用 SMTP 验证功能
$mail->Username = 'xxx@qq.com'; //SMTP 用户名
$mail->Password = 'xxxxxxxxxx'; //SMTP 密码
$mail->SMTPSecure = 'TLS'; //安全协议,可以注释掉 如TLS,SSL
$mail->Port = 465; //SMTP 端口号
$mail->setFrom('xxx@qq.com', '发送人'); //一个发件人
$mail->addAddress('yyy@qq.com', '收件人'); //多个收件人
$mail->addAttachment('D:/text.txt', '搜索.txt'); //多个附件
$mail->isHTML(true); //是否为html格式
$mail->Subject = '邮件标题';
$mail->Body = '邮件体<b>加粗</b>';
$mail->AltBody = '纯文本的邮件描述';
if(!$mail->send()) {
echo '发送失败: ' . $mail->ErrorInfo;
} else {
echo '发送成功';
}
?>
加载 TCPDF
L::open('pdf') 详细 v6.2.13
<?php
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// 添加一个页面
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
// 设置左边距, 上边距, 右边距
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
// 设置溢出自动添加页面, 下边距
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
// 设置左内边, 上内边, 右内边, 下内边
$pdf->setCellPaddings(0, 0, 0, 0);
// 设置页眉高, 页尾高
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// 去掉头尾横线
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// 设置px与实际长度比
$pdf->setImageScale(1.3);
// 设置可显示中文的字体
$pdf->SetFont('stsongstdlight', '', 14, '', true);
$pdf->AddPage();
$html = <<<EOD
可包括图片和连接的HTML文本
EOD;
// 设置当前页面内容
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
// 重置头模版
$pdf->resetHeaderTemplate();
// 添加新页眉
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 002');
// 添加新页
$pdf->AddPage();
// 输出 PDF, "I"=IO 流, "S"=返回字符串
$pdf->Output('example_001.pdf', 'I');
?>
加载 PHPRPC
L::open('pdf') 详细 v3.0.1
<?php
//PHP 服务端
L::open('phprpc');
function test($name) {
echo '输出的内容';
return '返回的内容' . $name;
}
$server = new PHPRPC_Server();
$server->add('test');
$server->start();
?>
<?php
//PHP 客户端
L::open('phprpc');
$client = new PHPRPC_Client('http://localhost/demo.php'); //服务端的网址
echo '返回信息: ', $client->test(123), "<br>\n"; //返回的内容123
echo '输出信息: ', $client->getOutput(), "<br>\n"; //输出的内容
echo '错误信息: ', $client->getWarning(), "<br>\n"; //错误信息
?>
//JAVA 客户端
import org.phprpc.PHPRPC_Client;
import org.phprpc.util.AssocArray;
import org.phprpc.util.Cast;
import java.util.Set;
import java.util.Map.Entry;
public class demo {
public static void main(String[] args) {
PHPRPC_Client client = new PHPRPC_Client("http://localhost/demo.php");
Object[] params = new Object[]{new Object[]{"参数1"}, "参数2"};
AssocArray array = (AssocArray)client.invoke("getSkuInfo", params);
Set<Entry<String, AssocArray>> sets = array.toHashMap().entrySet();
for(Entry<String, AssocArray> item : sets) {
System.out.print("键名: " + item.getKey() + ", ");
System.out.print("文本: " + Cast.toString(item.getValue().get("cname")) + "\n");
}
}
}