PHP中運(yùn)行python文件 讀取word文檔
1、檢查是否禁用函數(shù)exec 或 system 打開(kāi)
2、incov可解決中文亂碼問(wèn)題
3、直接新建PHP文件類方法
public function python() {
header("content-type:text/html;charset=utf-8");
$c = "D:\\phpStudy\\PHPTutorial\\WWW\\tp2\\1.py";
$python = exec("python $c");
$python = iconv('gbk', 'utf-8', $python);
dump($python);
}
4、引入python文件1.py
python需安裝docx擴(kuò)展 命令行輸入 pip install python-docx 安裝
import docx import os file=docx.Document("\ceshi.docx") print("段落數(shù):"+str(len(file.paragraphs))) text="" for i in range(len(file.paragraphs)): text += file.paragraphs[i].text i=i-1 print("第"+str(i)+"段的內(nèi)容是:"+file.paragraphs[i].text) print(text)

浙公網(wǎng)安備 33010602011771號(hào)