Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: split name

  1. #1
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post

    split name

    Hi guys, If I have a file name for example: image.jpg ,how can I split the file extention and save it in a variable and the rest in another variables?
    Im a noop coder

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by skmd View Post
    Hi guys, If I have a file name for example: image.jpg ,how can I split the file extention and save it in a variable and the rest in another variables?
    Im a noop coder
    link to php:

    http://www.php.net/manual/en/

    link to your answer:

    http://www.php.net/manual/en/function.basename.php

    best regards

  • #3
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    I read it but it doesnt fit my needs.
    in that method you should know what type if file u r going to split it
    but in my case they are all images .jpg .gif .png
    besides i want the rest of the file name to be saved in a variable.
    i there any other way

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by skmd View Post
    I read it but it doesnt fit my needs.
    in that method you should know what type if file u r going to split it
    but in my case they are all images .jpg .gif .png
    first link was for this case.

    besides i want the rest of the file name to be saved in a variable.
    i there any other way
    try this:

    http://www.php.net/manual/en/function.pathinfo.php

    pathinfo return all components by default.

    best regards.

  • #5
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    the $path_parts['filename'] required php v5.2 and I dont have it
    is there another solution???
    Last edited by skmd; 12-22-2007 at 09:20 PM.

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by skmd View Post
    the $path_parts['filename'] required php v5.2 and I dont have it
    is there another solution???
    on the same page:

    http://www.php.net/manual/en/function.pathinfo.php

    scroll down and you'll find this:
    Code:
     anders.jenbo()pc.dk
    11-Sep-2007 02:34
    Heres a funciton to get the same results from php 4+ but you will have to call pathinfo_filename() instead of pathinfo().
    
    <?php
    if(version_compare(phpversion(), "5.2.0", "<")) {
        function pathinfo_filename($path) {
            $temp = pathinfo($path);
            if($temp['extension'])
                $temp['filename'] = substr($temp['basename'],0 ,strlen($temp['basename'])-strlen($temp['extension'])-1);
            return $temp;
        }
    } else {
        function pathinfo_filename($path) {
            return pathinfo($path);
        }
    }
    ?>
    best regards

  • #7
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    I tried to use but every time I get "Array" instead of the file name
    Can you please try it for me or give mee another solution !!

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by skmd View Post
    I tried to use but every time I get "Array" instead of the file name
    Can you please try it for me or give mee another solution !!
    that's because it return a array.

    try this( untested):

    PHP Code:
    $parts pathinfo_filename($path);
    print_r($parts); // to see how it look
    $filename $parts['filename']; 
    PS: I can't test it, I have php 5.2 installed
    best regards
    Last edited by oesxyl; 12-22-2007 at 10:51 PM.


  •  

    Posting Permissions

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