Results 1 to 8 of 8

Thread: split explode?

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default split explode?

    I'm trying to split up a file name its name is in this format ####_ALPHA_VERSION.extension.

    I wrote this.

    PHP Code:
    $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.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here:
    PHP Code:
    $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.
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    bluewalrus (05-28-2009)

  4. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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.

  5. #4
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I think POST should be fine for this. But does it work in your case?
    Jeremy | jfein.net

  6. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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

    Code:
    $filename_tmp = $_FILES['filename']['tmp_name'];
    $filename_size = $_FILES['filename']['size'];
    with

    Code:
    $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.

  7. #6
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I don't get it, can you be a bit more specific.
    Jeremy | jfein.net

  8. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    If i have this

    PHP Code:
    $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
    PHP Code:
    $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.

  9. #8
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Instead of $_POST['filename'] try $_FILES['filename']['name']. Good luck!
    Jeremy | jfein.net

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •