You are here

public function FrxControls::csvdocument in Forena Reports 7

Same name and namespace in other branches
  1. 6.2 plugins/FrxControls.inc \FrxControls::csvDocument()
  2. 6 plugins/FrxControls.inc \FrxControls::csvdocument()
  3. 7.2 plugins/FrxControls.inc \FrxControls::csvDocument()

File

plugins/FrxControls.inc, line 124
contains various methods for extending report formating, layout, transformation and design.

Class

FrxControls
@file contains various methods for extending report formating, layout, transformation and design.

Code

public function csvdocument($body, $options) {
  $doc = new DOMDocument();
  $doc->strictErrorChecking = FALSE;
  $xmlBody = '<?xml version="1.0" encoding="UTF-8"?>' . $body;
  $doc
    ->loadHTML($xmlBody);
  $xml = simplexml_import_dom($doc);
  $rows = $xml
    ->xpath('//tr');
  if ($rows) {
    foreach ($rows as $row) {
      foreach ($row as $column) {
        $value = $column
          ->asXML();
        $value = strip_tags($value);
        $value = str_replace('"', '""', $value);
        $value = str_replace(array(
          "\n",
        ), '', $value);
        $value = '"' . $value . '",';
        $output .= $value;
      }
      $output .= "\n";
    }
  }
  return $output;
}