public function create_file($table)
{

$data = array();
$doc = new DOMDocument();
$doc->loadHTML($table);
$file = array();

$tables = $this->tables_to_array($table);
$node = $doc->getElementsByTagName(“h2”);

if (!file_exists(CSVPATH)) {
mkdir(CSVPATH, 0777, true);
}
for ($c = 0; $c length; $c++)
{
$text[$c] = $doc->saveXML($node->item($c));
$filename = strip_tags($text[$c]);
$pattern = ‘/ /’;
$replacement = ‘_’;
$filename = preg_replace($pattern, $replacement, $filename);

$print = “”;

foreach ($tables[$c] as $rows)
{
foreach ($rows as $cols)
{
$print .= “$cols,”;
}
$print .= “\n”;
$fp = fopen(CSVPATH . “$filename.csv”, “w”);
fwrite($fp, $print);
}

$print = ”;

$file[] = CSVPATH . “$filename.csv”;
}

return $file;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s