目前,我正在进行一个项目,其中一个 PHP 脚本从ftp://ftp.sec.gov获取索引文件并将所有公司信息放入数据库中。然后,第二个 PHP 脚本从 SEC 获取原始文本文件并将其保存在本地以供处理。
可以在此处找到原始文本文件的示例 -
ftp://ftp.sec.gov/edgar/data/2488/0000002488-15-000028.txt
可以在此处找到最终结果的示例 - http://www.sec.gov/Archives/edgar/data/1084869/000143774915020024/flws20150927_10q.htm
目标是能够像许多公司一样以格式化的方式呈现文件,但问题是我似乎无法弄清楚它是如何可靠地为每个文件完成的。一些文件似乎有 XML,其他文件似乎有 HTML
我如何能够可靠地生成原始文本文件的格式化版本?
我拥有的当前代码 -
$db_hostname = "localhost";
$db_username = "username";
$db_password = "password";
$db_database = "database";
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());
$query = "SELECT * FROM company WHERE company = '1 800 FLOWERS COM INC' AND date = '2015-08-06'";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
$file = "ftp://ftp.sec.gov/" . $row[4];
$text = file_get_contents($file);
if($text === false){
echo "error downloading file $row[4]\n";
continue;
}
$tarray = explode('<SEQUENCE>', $text);
for($i = 1; $i < count($tarray); $i++){
$a = strstr($tarray[$i], '<HTML>');
if($a == false)continue; //means that there is no html document in this sequence
$html = strstr($a, '</HTML>', true);
$html.="</HTML>";
$running = $running . $html;
}
$temp = "cache.htm";
file_put_contents($temp, $running);
$name = $row[0] . "-" . $row[3] . ".pdf";
$name = str_replace(' ', '_', $name);
//$content = file_get_contents($row[2] . "-" . $row[1] . ".htm");
exec("D://wkhtmltopdf/bin/wkhtmltopdf.exe $temp $name");
unlink($temp);
//echo($row[0] . " created");
?>