如何在控制器Codeigniter中添加HTML?

时间:2018-10-02 02:45:54

标签: php html css codeigniter

我在codeIgniter中的内容控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class AutoLoadDiv extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $this->load->view('ngoding/AutoLoad');
    }

    public function getData() {

        $this->load->library('table');
        $err = file_get_contents("application\logs\log.php");
        $filestr = preg_replace(array('/(^|\R)ERROR\s*-\s*/', '/(^|\R)(.*?)\s*-->\s*/'), array('$1', '$1$2 '), $err);
        $arraySpacing = nl2br($filestr);
        $arr = explode("\n", $arraySpacing);

        for ($i = count($arr)-1; $i >= 0; $i--) {
            echo "<html><body><table><tr><td>$arr[$i];</td></tr></table></body>/html>";
        }
      }
  }

我在控制器中制作表格时遇到问题,我想像这样打印表格

enter image description here

我有看法:

https://codeshare.io/GqyWmk

1 个答案:

答案 0 :(得分:0)

要在图像中打印表格,您需要像这样更改代码。

假设文件中只有4列:

   $output = "<html><body><table>"; // Keep this outside for loop to print only once.


   var $j = 0;
   for ($i = count($arr)-1; $i >= 0; $i--) {

      if ($j % 4 == 0) {
          $output.="<tr>";
      }
      $output.="<td>$arr[$i]</td>"; // Adding new row in your output varible.
      if ($j % 4 == 0) {
         $output.="</tr>";
      }
     ++$j;
     }
        $output.="</table></body>/html>"; // This should also be outside because you want to close table, body and html only once.
        echo $output; // Printing your final data.

您可以根据需要修改此代码;