Note that there are some explanatory texts on larger screens.

plurals
  1. POremoving parts of two strings of an array
    text
    copied!<p>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.</p> <pre><code> { ["parent_directory_one/child_directory_one"]=&gt; int(0) ["parent_directory_one/child_directory_two"]=&gt; int(1) } </code></pre> <p>how to change the above to the following:</p> <pre><code> { ["child_directory_one"]=&gt; int(0) ["child_directory_two"]=&gt; int(1) } </code></pre> <p>then how to change this as follows:</p> <pre><code> { ["parent_directory_one/child_directory_one/child_files_one"]=&gt; int(0) ["parent_directory_two/child_directory_two/child_files_two"]=&gt; int(1) } </code></pre> <p>to the this:</p> <pre><code> { ["child_files_one"]=&gt; int(0) ["child_files_two"]=&gt; int(1) } //controller// </code></pre> <p>ok here's some examples of what I tried and the view files are under construction:</p> <pre><code> //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; </code></pre> <p>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.</p> <pre><code> //CONTROLLER// $rm_targets = $this-&gt;input-&gt;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; </code></pre> <p>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) }</p> <p>I'm not sure how the view or controller need to be setup at the moment.</p> <p>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.</p> <pre><code> //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; </code></pre> <p>here's the view file which under construction I want to note again so the loops are not yet correct:</p> <pre><code> //VIEW// &lt;?php if(!defined('BASEPATH'))exit('No direct script access allowed'); ?&gt; &lt;?php echo form_open('test_sftp/test_function')?&gt; &lt;select name="pt_rm_dirs" multiple size="10"&gt; &lt;option value="select one"&lt;?php echo set_select('pt_rm_dirs', 'select_one');?&gt; &gt;select&amp;nbsp;one&lt;/option&gt; &lt;?php foreach($list_rm as $folder_rm_dirs =&gt; $contents_rm_dirs):?&gt; &lt;option value="&lt;?php echo $folder_rm_dirs?&gt;"&lt;?php echo set_select('pt_rm_dirs', '$folder_rm_dirs');?&gt; &gt;&lt;?php echo $folder_rm_dirs?&gt;&lt;/option&gt; &lt;?php endforeach;?&gt; &lt;?php unset($contents_rm_dirs);?&gt; </code></pre> <p> Step&nbsp;2: <p>Specify new names for remote directories selected:</p></p> <pre><code> &lt;select name="ct_rm_subdirs" multiple size="10"&gt; &lt;option value="select one"&lt;?php echo set_select('ct_rm_subdirs', 'select_one');?&gt; &gt;select&amp;nbsp;one&lt;/option&gt; &lt;?php foreach($list_sub_rm as $sub_folder_rm):?&gt; &lt;option value="&lt;?php echo $sub_folder_rm?&gt;"&lt;?php echo set_select('ct_rm_subdirs', '$sub_folder_rm');?&gt; &gt;&lt;?php echo $sub_folder_rm?&gt;&lt;/option&gt; &lt;?php endforeach;?&gt; &lt;?php unset($sub_contents_rm);?&gt; &lt;/select&gt; &lt;select name="rm_sub_dirs_files" multiple size="15"&gt; &lt;option value="select one"&lt;?php echo set_select('rm_sub_dirs_files', 'select_one');?&gt; &gt;select&amp;nbsp;one&lt;/option&gt; &lt;?php foreach($list_sub_rm as $sub_folder_rm =&gt; $sub_contents_rm):?&gt; &lt;optgroup label="&lt;?php echo $sub_folder_rm?&gt;"&gt; &lt;?php foreach($sub_contents_rm as $files):?&gt; &lt;option value="&lt;?php echo $files?&gt;"&lt;?php echo set_select('rm_sub_dirs_files', '$files');?&gt; &gt;&lt;?php echo $files?&gt;&lt;/option&gt; &lt;?php endforeach;?&gt; &lt;?php endforeach;?&gt; &lt;?php unset($sub_contents_rm);?&gt; &lt;?php unset($files);?&gt; &lt;/optgroup&gt; &lt;/select&gt; &lt;?php echo form_submit('submit', 'Submit');?&gt; &lt;?php echo form_close()?&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php echo form_close();?&gt; </code></pre> <p>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.</p> <pre><code>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; </code></pre> <p>Any help greatly appreciated!!! Thanks!!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload