Welcome Guest, Not a member yet? Register   Sign In
problems with using explode("t", $string) from form_textarea
#1

[eluser]xorzizten[/eluser]
Hi!
I have a little problem exploding a string from form_textarea on \t. It does not seem that it posts the \t at all??

My controller
Code:
public function add_inventory()
{
  if($this->input->post('submit_inv'))
  {
   $lines = explode("\n", $this->input->post('inv_list'));
   foreach($lines AS $line)
   {
    $items[] = explode("\t", $line);
   }
  }
  
  $this->load->view('template/header');
  $this->load->view('economysystem/add_inventory', array('lines' => $items));
  $this->load->view('template/footer');
}

My view;
Code:
<h1>Add New Inventory List</h1>

&lt;?php
if(validation_errors())
{
echo validation_errors();
}
echo form_open(current_url());
$data = array(
'name' => 'inv_list',
'id' => 'inv_list',
'rows' => '40',
'cols' => '80',
);
echo form_textarea($data).'<br />';
echo form_submit('submit_inv','Add Inventory');
echo form_close();
?&gt;

I'm using a copy/paste from a list which contains tabs. One line from this looks like;
Code:
2 ACA/AS Civilian Uniform Arctic Glasses (M) 1 51.00 PED CARRIED
the same line with indicators at where the tab is located.
Code:
2 [tab] ACA/AS Civilian Uniform Arctic Glasses (M) [tab] 1 [tab] 51.00 PED [tab] CARRIED

Run through my function it produces;
Code:
Array
(
    [0] => Array
        (
            [0] => 2 ACA/AS Civilian Uniform Arctic Glasses (M) 1 51.00 PED CARRIED
        )

)
Which is not what i want! Sad

I made this code in an stand alone file outside CI;
Code:
&lt;form acti method="post"&gt;
&lt;textarea name="inv_list" id="inv_list" rows="40" cols="80"&gt;&lt;/textarea>
&lt;input type="submit" name="submit_inv" value="Add Inventory" /&gt;
&lt;/form&gt;
&lt;?php
if(isset($_POST['submit_inv']))
{
$lines = explode("\n", $_POST['inv_list']);
foreach($lines AS $line)
{
  $items[] = explode("\t", $line);
}
echo '<pre>';
print_r($items);
echo '</pre>';
}
?&gt;

And this produces;

Code:
Array
(
    [0] => Array
        (
            [0] => 2
            [1] => ACA/AS Civilian Uniform Arctic Glasses (M)
            [2] => 1
            [3] => 51.00 PED
            [4] => CARRIED
        )

)

Which is what i'm looking for Smile

Hope my problem makes any cense, and that someone may help me produce the desired result Smile

Kind regards
Kjell-Arne


Messages In This Thread
problems with using explode("t", $string) from form_textarea - by El Forum - 03-05-2013, 09:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB