0

I'm trying to remove two parts of two strings of an array which is output from ftp_nlist. I am working with CI. ALSO PLEASE NOTE THE MULTI SELECT LIST IN VIEW ARE BEING WORKED ON AND ARE NOT CORRECT CODE WISE. HOWEVER I THOUGHT I SHOULD DISCLOSE THE OTHER SELECT LISTS WHICH SHOWS THE COMPLETE VIEW FILE.

    { ["parent_directory_one/child_directory_one"]=> int(0) ["parent_directory_one/child_directory_two"]=> int(1) }

how to change the above to the following:

    { ["child_directory_one"]=> int(0) ["child_directory_two"]=> int(1) }

then how to change this as follows:

    { ["parent_directory_one/child_directory_one/child_files_one"]=> int(0) ["parent_directory_two/child_directory_two/child_files_two"]=> int(1) }

to the this:

      { ["child_files_one"]=> int(0) ["child_files_two"]=> int(1) }
   //controller//

ok here's some examples of what I tried and the view files are under construction:

    //read default remote
    $glue = '/'; $strs = ''; $root_piece_rm = ltrim($strs, './'); 

    $list_rm = ftp_nlist($conn_id,$root_piece_rm);

    $list_rm = array_flip($list_rm);

    $data['list_rm'] = $list_rm;
    //end read default remote


    if($rm_targets):

    $glue = '/'; $list_sub_rm = ftp_nlist($conn_id,$rm_targets);

    foreach($list_sub_rm as $keys):

        $list_sub_rm  = ltrim($keys,$rm_targets.$glue);

    $data['list_sub_rm'] = var_dump(array($list_sub_rm));

    endforeach;

    endif;

However the following code for the sub directories is the problem and I think ltrim isn't going to work. However the var_dump is outputting the strings trimmed according to the pattern which is $rm_targets.$glue that needs to be removed only showing the sub-directories.

    //CONTROLLER//
    $rm_targets = $this->input->post('pt_rm_dirs',TRUE);

if($rm_targets):

$glue = '/'; $list_sub_rm = ftp_nlist($conn_id,$rm_targets);

$list_sub_rm = array_flip($list_sub_rm);

$list_sub_rm = array_keys($list_sub_rm);

foreach($list_sub_rm  as $index):

$eraser = ltrim($index,$rm_targets.$glue);

endforeach;

$data['list_sub_rm'] = $list_sub_rm;

endif;

Again essentially I need to remove the parent directories from the following strings of an array { ["jm_gallery/new_test_origs"]=> int(0) ["jm_gallery/test_thumbs"]=> int(1) }

I'm not sure how the view or controller need to be setup at the moment.

The output I get from var_dump below is what I need to show in the multi select list. It is essentially the sub directories but the forward slash and parent removed. I haven't had difficulty with such a scenario until I started working with ftp_nlist and it is extremely disturbing.

    //CONTROLLER//
if($rm_targets):

$glue = '/'; $list_sub_rm = ftp_nlist($conn_id,$rm_targets);

foreach($list_sub_rm as $keys):

    $list_sub_rm  = ltrim($keys,$rm_targets.$glue);

$data['list_sub_rm'] = var_dump(array($list_sub_rm));

endforeach;

endif;

here's the view file which under construction I want to note again so the loops are not yet correct:

    //VIEW//
    <?php if(!defined('BASEPATH'))exit('No direct script access allowed'); ?>

    <?php echo form_open('test_sftp/test_function')?>

    <select name="pt_rm_dirs" multiple size="10">
    <option value="select one"<?php echo set_select('pt_rm_dirs', 'select_one');?>   >select&nbsp;one</option>
    <?php foreach($list_rm as $folder_rm_dirs => $contents_rm_dirs):?>
    <option value="<?php echo $folder_rm_dirs?>"<?php echo set_select('pt_rm_dirs', '$folder_rm_dirs');?> ><?php echo $folder_rm_dirs?></option>
    <?php endforeach;?>
    <?php unset($contents_rm_dirs);?>

Step 2:

Specify new names for remote directories selected:

    <select name="ct_rm_subdirs" multiple size="10">
    <option value="select one"<?php echo set_select('ct_rm_subdirs', 'select_one');?> >select&nbsp;one</option>
    <?php foreach($list_sub_rm as $sub_folder_rm):?>
    <option value="<?php echo $sub_folder_rm?>"<?php echo set_select('ct_rm_subdirs', '$sub_folder_rm');?> ><?php echo $sub_folder_rm?></option>
    <?php endforeach;?>
    <?php unset($sub_contents_rm);?>
    </select>

    <select name="rm_sub_dirs_files" multiple size="15">
    <option value="select one"<?php echo set_select('rm_sub_dirs_files', 'select_one');?> >select&nbsp;one</option>
    <?php foreach($list_sub_rm as $sub_folder_rm => $sub_contents_rm):?>
    <optgroup label="<?php echo $sub_folder_rm?>">
    <?php foreach($sub_contents_rm as $files):?>
    <option value="<?php echo $files?>"<?php echo set_select('rm_sub_dirs_files', '$files');?> ><?php echo $files?></option>
    <?php endforeach;?>
    <?php endforeach;?>
    <?php unset($sub_contents_rm);?>
    <?php unset($files);?>
    </optgroup>
    </select> 
    <?php echo form_submit('submit', 'Submit');?>
    <?php echo form_close()?>

    </body>
    </html>
    <?php echo form_close();?>

UPDATE: when I var_dump the code below the strings are changed as I need them but why can't I echo them via the View? I tried converting the strings to an array which became problematic.

if($rm_targets):

$glue = '/'; 

$list_sub_rm = ftp_nlist($conn_id,$rm_targets);

foreach($list_sub_rm as $keys):

$list_sub_rm = ltrim($keys,$rm_targets.$glue);

$data['list_sub_rm'] = var_dump($list_sub_rm);

    endforeach;

endif; 

Any help greatly appreciated!!! Thanks!!!

4

1 に答える 1

0

ファイル名があなたの配列のキーであるように見えます。

foreach ( $list_sub_rm as $key => $value ) {
    $key = preg_replace("#.*/([^/]*)$#", "$1", $key);
    $newArray[$key] = $value;
}
于 2012-06-29T05:47:26.150 に答える