-7

trim() doesnt't work, I have no idea why. I adding model is not important, sorry for the first add.

When I run it and load row with 123 123 123 from Excel, this doesn't make me 123123123

How can I fix it?

If you will need the model, please write a comment.

PHP a bit controller

class Kontroler extends CI_Controller {

    public function upload()
    {
        $file = 'przyklad kk.xls';
        $this->load->library('excel');
        $this->excel=PHPExcel_IOFactory::load($file);  
        $this->excel->setActiveSheetIndex(0);
        $array = $this->excel->getActiveSheet()->toArray(null, true, true, true);

        for ($i = 2; $i <= count($array); $i++) {
            if ($array[$i]['A'] == NULL) $array[$i]['A'] = 'Brak';
            if ($array[$i]['B'] == NULL) $array[$i]['B'] = 'Brak';
            if ($array[$i]['C'] == NULL) $array[$i]['C'] = '00-000';
            if ($array[$i]['F'] == NULL) $array[$i]['F'] = 'Brak';
            if ($array[$i]['G'] == NULL) $array[$i]['G'] = 'Brak';
            if ($array[$i]['D'] == NULL) $array[$i]['D'] = 'Brak';
            if ($array[$i]['H'] == NULL) $array[$i]['H'] = 'Brak';
            if ($array[$i]['E'] == NULL) $array[$i]['E'] = 'Brak';
            if ($array[$i]['J'] == NULL) $array[$i]['J'] = 'Brak';
            if ($array[$i]['I'] == NULL) $array[$i]['I'] = 'brak@brak.pl';
            if ($array[$i]['N'] == NULL) $array[$i]['N'] = 'Brak';

            $tab[$i]['City'] = $array[$i]['D'];
            $tab[$i]['ContactPersonName'] = $array[$i]['F'];
            $tab[$i]['ContactPersonSubname'] = $array[$i]['G'];
            $tab[$i]['Email'] = $array[$i]['I'];
            $tab[$i]['Name'] = $array[$i]['A'];
            $tab[$i]['Phone'] = $array[$i]['H'];
            $tab[$i]['PostCode'] = $array[$i]['C'];
            $tab[$i]['Potential'] = $array[$i]['J'];
            $tab[$i]['Powiat'] = $array[$i]['E'];
            $tab[$i]['Street'] = $array[$i]['B'];
            $tab[$i]['ID_GR'] = $array[$i]['L'];
            $tab[$i]['ID_RM'] = $array[$i]['M'];
            $tab[$i]['ID_PR'] = $array[$i]['N'];    

            $Name = trim($array[$i]['A']);
            $Street = trim($array[$i]['B']);
            $PostCode = trim($array[$i]['C']);
            $City = trim($array[$i]['D']);
            $ContactPersonName = trim($array[$i]['F']);
            $ContactPersonSubname = trim($array[$i]['G']);
            $Email = trim($array[$i]['I']);
            $Name = trim($array[$i]['D']);
            $Phone = trim($tab[$i]['Phone']);
            $Powiat = trim($array[$i]['E']);
            $Potential = trim($array[$i]['J']);         
            $ID_GR = trim($tab[$i]['ID_GR']);
            $ID_RM = trim($array[$iQ]['M']);
            $ID_PR = trim($array[$i]['N']);             
        }
        $this->model->insert_from_file_kk($tab);
    }

    public function show()
    {
        $data['rekordy'] = $this->model->get_rek();
        $this->load->view('widok', $data);
    }
}

PHP view

<div id="content">
<table border=1>
<tr>
<td>Nazwa</td><td>Ulica</td><td>Kod pocztowy</td><td>Miasto</td><td>Powiat</td><td>Imie os kontaktowej</td><td>Nazwisko os kontaktowej</td><td>Telefon</td><td>Email</td>     <td>Potencjal</td>
<td>ID_PR</td><td>ID_GR</td><td>ID_RM</td>
</tr>
<?php

foreach ($rekordy as $rekord)
{
    echo "
    <tr>
    <td>$rekord->Name</td>
    <td>$rekord->Street</td>
    <td>$rekord->PostCode</td>
    <td>$rekord->City</td>
    <td>$rekord->Powiat</td>
    <td>$rekord->ContactPersonName</td>
    <td>$rekord->ContactPersonSubname</td>
    <td>$rekord->Phone</td>
    <td>$rekord->Email</td>
    <td>$rekord->Potential</td>
    <td>$rekord->ID_PR</td>
    <td>$rekord->ID_GR</td>
    <td>$rekord->ID_RM</td>
    </tr>
";

}

?>
</table>
</div>
4

2 回答 2

4

When I run it and load row with 123 123 123 from excel this dont make me 123123123.

That's what trim($str) is supposed to do: stripping whitespaces from the beginning and end of $str. Attention: only whitespace from the beginning and end. See the documentation.

To achieve what you want, simply replace all spaces with an empty string:

$subject = "123 123 123";
$output = str_replace(" ", "", $subject);
echo $output;

It outputs

123123123

于 2013-10-09T12:19:28.270 回答
1

I might be way off here, but it looks like you have forgotten to wrap your PHP code in PHP tags:

<td><?php echo $rekord->Name; ?></td>
<td><?php echo $rekord->Street; ?></td>
<td><?php echo $rekord->PostCode; ?></td>
于 2013-10-09T10:35:21.593 回答