簡體   English   中英

使用php從html頁面的特定行中提取數據

[英]extract data from particular line in html page using php

這是我最初的問題,我被困住並試圖通過嘗試解決問題並再次陷入困境

我需要從pdf中提取候選人的姓名及其ID,因此在使用pdfparser之后,我提取了文本並使用php下載了html頁面

<?php
$filename = 'filename.html';
header('Content-disposition: attachment; filename=' . $filename);
header('Content-type: text/html');
// ... the rest of your file
?>
<?php

// Include Composer autoloader if not already done.
include 'C:\Users\amite\Downloads\pdfparser-master (1)\pdfparser-master\vendor\autoload.php';

// Parse pdf file and build necessary objects.
$parser = new  \Smalot\PdfParser\Parser();
$pdf    = $parser->parseFile('C:\Users\amite\Desktop\Data\001.ApplicationForm-CSE-2015-1-omokop (3).pdf');

$text = $pdf->getText();
echo $text;


?>

我這樣做是因為我需要的信息位於視圖源頁面的第12行和第13行,這是我需要的所有pdf的信息,因此下載html文件后,我使用了下面的代碼來查看html文件的源頁面

<?php
show_source("filename.html");
?> 

現在,當我運行上述程序時,我得到了下載的html文件的源頁面,現在我需要從第12行和第13行提取數據,程序的輸出如下所示:-

<html>
 text
 text
text
text 
text 
text   

除html標簽外沒有其他標簽,我需要的信息在第12,13行,如果您需要任何說明,請問我,我會告訴您。 如果還有另一種方式告訴我,我應該如何從第12,13行提取文本。 我再次陷入困境,如果問題不清楚,我將予以澄清或改善,請幫助我。

這是您需要的嗎?

<?php
$str = "1text
 2text
3text
4text 
5text 
6text
7text 
8text 
9text
10text 
11text 
12text
13text
";
$k = array_slice(explode("\n",$str),11,1);
print_r($k);

使用$source = file('filename.html');將文件源存儲到數組中$source = file('filename.html'); 並通過數組索引11和12提取第12和13行,就像echo $source[11]; //line 12 echo $source[11]; //line 12

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM