View Full Version : split explode?
bluewalrus
05-21-2009, 03:18 AM
I'm trying to split up a file name its name is in this format ####_ALPHA_VERSION.extension.
I wrote this.
$name = $_POST['filename'];
$seperate = explode("_", $name);
$articleID = $seperate[0];
$articlename = $seperate[1];
$articleversiontmp = $seperate[2];
list($articleversion, $extension) = split('.', $articleversiontmp);
echo $name . "<br />" . $articleversion . "<br />" . $articlename . "<br />" . $articleID . "<br />" . $articleversiontmp . "<br />" . $extension;
Which i thought would echo
####_ALPHA_VERSION.extension
VERSION
ALPHA
####
extension
But it is instead echoing
####_ALPHA_VERSION.extension
ALPHA
####
VERSION.extension
I don't know if it is because the . from the file name is not a normal character or if it is because it is coming from an explode or something else.
Here:
$name = array();
$name[0] = $_POST['filename'];
$name[1] = explode("_", $name[0]);
$name[2] = explode(".", $name[1][2]);
echo $name[0]."<br />".$name[2][0]."<br />".$name[1][1]."<br />".$name[1][0]."<br />".$name[2][1];
?>
That should do it. ;)
bluewalrus
05-28-2009, 07:43 PM
Yup, that did it again. Thanks.
I want to use this along with the $_FILES is that possible or is there a way to have a hidden input field grab the value and use that. I think my current problem is that I'm trying to use $_POST and $_FILES on the same input value.
I think POST should be fine for this. But does it work in your case?
bluewalrus
05-28-2009, 07:57 PM
I'm trying to add another function within it to upload the file and i need the temporary address of it. So I'm using this
$filename_tmp = $_FILES['filename']['tmp_name'];
$filename_size = $_FILES['filename']['size'];
with
$name2 = array();
$name2[0] = $_POST['filename'];
$name2[1] = explode("_", $name2[0]);
$name2[2] = explode(".", $name2[1][2]);
But depending on the order if the $_post is first the 'name' values show up. if the $_files is first the 'filenames' values show up.
I don't get it, can you be a bit more specific.
bluewalrus
05-28-2009, 08:25 PM
If i have this
$name = array();
$name[0] = $_POST['filename'];
$name[1] = explode("_", $name[0]);
$name[2] = explode(".", $name[1][2]);
echo $name[0]."<br />".$name[2][0]."<br />".$name[1][1]."<br />".$name[1][0]."<br />".$name[2][1];
$filename = $_FILES['filename']['name'];
$filename_tmp = $_FILES['filename']['tmp_name'];
$filename_size = $_FILES['filename']['size'];
echo "name:" . $filename . "temp_name:" . $filename_tmp . "size:" . $filename_size . "<br />";
it echos the contents of this
echo $name[0]."<br />".$name[2][0]."<br />".$name[1][1]."<br />".$name[1][0]."<br />".$name[2][1];
correctly but leaves the other
echo "name:" . $filename . "temp_name:" . $filename_tmp . "size:" . $filename_size . "<br />";
blank. Then if I reverse it like this
$filename = $_FILES['filename']['name'];
$filename_tmp = $_FILES['filename']['tmp_name'];
$filename_size = $_FILES['filename']['size'];
echo "name:" . $filename . "temp_name:" . $filename_tmp . "size:" . $filename_size . "<br />";
$name = array();
$name[0] = $_POST['filename'];
$name[1] = explode("_", $name[0]);
$name[2] = explode(".", $name[1][2]);
echo $name[0]."<br />".$name[2][0]."<br />".$name[1][1]."<br />".$name[1][0]."<br />".$name[2][1];
It echos the contents of
echo "name:" . $filename . "temp_name:" . $filename_tmp . "size:" . $filename_size . "<br />";
correctly but then this
echo $name[0]."<br />".$name[2][0]."<br />".$name[1][1]."<br />".$name[1][0]."<br />".$name[2][1];
is blank, which makes me think it is once i use the post or the file i can't use the other on that value.
Instead of $_POST['filename'] try $_FILES['filename']['name']. Good luck!
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.