Jump to content

explode function


seularts

Recommended Posts

How do i explode a path such as: c:/path1/path2/path3/file.exe, by counting the words(because the path can vary) in the path and exploding them through "/", and then exploding again the last 2 words delimited through "." remaining only with the word file.

Can anyone help me with this!?

Link to comment
Share on other sites

<?

$str = "c:/etc/asd/ada/fda.jpg";

$primu= explode("/",$str,5);

$doi=explode(".",$primu[4]);

echo $doi[0];

?>

 

The result is the word "fda", but here i`m counting the word manualy, i would like something like a loop for the arry count of the words, if that is possible:)

Link to comment
Share on other sites

this is the output: etc/asd/ada/fda, so i still remain with the problem of selecting the last word from the count. because the path could vary from 5 to even 20 words.. so there wouldn't be any hope to select thw eord bi hand imput, so i do need a loop

Link to comment
Share on other sites

here try this

$filename = ereg("/(.*\..{3,4})"), $str, $arr) ? $arr[1] : "No File Name";

 

you shouldn't need a loop if you just need the filename like that.

Regex can chop it all up no matter how long it is

 

 

EDIT: I had to edit the code btw

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.