Jump to content

[SOLVED] Array of Issues


phpretard

Recommended Posts

I am trying to take away "../documents/" and just end up with:

 

$FinalArray = array("Agreement.doc","Overview.pdf");

 

At the end of the code I would like an array with these values:

 

This code ain't workin'...

 

<?

$file_1="../documents/Agreement.doc";
$file_2="../documents/Overview.pdf";

$InputFile = array("Appraisal Agreement","Overview");

$files = array("$file_1","$file_2");


foreach($files as $filenames){

$ext = end(explode('.', $filenames));

$ext = substr(strrchr($filenames, '.'), 1);

$ext = substr($filenames, strrpos($filenames, '.') + 1);

$ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filenames);

$exts = split("[/\\.]", $filenames);

$n = count($exts)-1;
$ext = $exts[$n];

$THE_EXT.$ext;

}

foreach($InputFile as $InputName){

$THE_NAME= $InputName;

}


$FinalArray = PROBLEM

?>

Link to comment
https://forums.phpfreaks.com/topic/147429-solved-array-of-issues/
Share on other sites

This gets it close:

 

$file_1="../documents/Appraisal Agreement.doc";
$file_2="../documents/Overview.pdf";

$InputFile = array("Appraisal Agreement","Overview");

$files = array("$file_1","$file_2");


foreach($files as $filenames){

$ext = end(explode('.', $filenames));

$ext = substr(strrchr($filenames, '.'), 1);

$ext = substr($filenames, strrpos($filenames, '.') + 1);

$ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filenames);

$exts = split("[/\\.]", $filenames);

$n = count($exts)-1;
$ext = $exts[$n];

$THE_EXT[]= ".".$ext;

}

foreach($InputFile as $InputName){

$THE_NAME[]= $InputName;

}

$FinalArray = array_merge($THE_NAME, $THE_EXT);

print_r ($FinalArray);

 

 

Array ( [0] => Appraisal Agreement [1] => Overview [2] => .doc [3] => .pdf )

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.