Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8162755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:50:06+00:00 2026-06-06T18:50:06+00:00

I’m trying to remove two parts of two strings of an array which is

  • 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!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:50:07+00:00Added an answer on June 6, 2026 at 6:50 pm

    It looks like the filenames are the keys in your array which kind of threw me.

    foreach ( $list_sub_rm as $key => $value ) {
        $key = preg_replace("#.*/([^/]*)$#", "$1", $key);
        $newArray[$key] = $value;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.