文件处理中的PHP面向对象概念

文件处理中的PHP面向对象概念,php,Php,我想从文本文件中读取内容,并使用PHP面向对象将其下载到pdf文件中。如何从文件中读取内容,与简单PHP相同吗?获取文件内容的最简单方法是: 您想知道如何使用面向对象的表示法获取文件的内容,或者如何将内容存储为对象,或者如何将内容移动到pdf中吗 假设最后2个: //First set the file path and get the contents of the file: $textfile->path = "path/to/file.txt"; $textfile->con

我想从文本文件中读取内容,并使用PHP面向对象将其下载到pdf文件中。如何从文件中读取内容,与简单PHP相同吗?

获取文件内容的最简单方法是:


您想知道如何使用面向对象的表示法获取文件的内容,或者如何将内容存储为对象,或者如何将内容移动到pdf中吗

假设最后2个:

//First set the file path and get the contents of the file:
$textfile->path = "path/to/file.txt";
$textfile->contents = file_get_contents($textfile->path);

//Next create the pdf, both as a handler and as a file on disk:
$pdf = PDF_new();
PDF_begin_document($pdf, "file.pdf", "");

//Then put the text file contents into the pdf:
PDF_show($pdf, $textfile->contents);

//Finally, save and close the pdf:
pdf_save($pdf); 
pdf_close($pdf); 
如果希望脚本从请求返回pdf而不是将其保存到服务器,只需将file.pdf更改为,并使用header函数设置文件名

//First set the file path and get the contents of the file:
$textfile->path = "path/to/file.txt";
$textfile->contents = file_get_contents($textfile->path);

//Next create the pdf, both as a handler and as a file on disk:
$pdf = PDF_new();
PDF_begin_document($pdf, "file.pdf", "");

//Then put the text file contents into the pdf:
PDF_show($pdf, $textfile->contents);

//Finally, save and close the pdf:
pdf_save($pdf); 
pdf_close($pdf);