...

View Full Version : split name



skmd
12-22-2007, 07:45 PM
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 :D

oesxyl
12-22-2007, 07:55 PM
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 :D

link to php:

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

link to your answer:

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

best regards

skmd
12-22-2007, 08:16 PM
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

oesxyl
12-22-2007, 08:28 PM
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.

skmd
12-22-2007, 09:15 PM
the $path_parts['filename'] required php v5.2 and I dont have it
is there another solution???

oesxyl
12-22-2007, 09:36 PM
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:


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

skmd
12-22-2007, 10:29 PM
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 !!

oesxyl
12-22-2007, 10:46 PM
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):



$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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum