Jump to content

Recommended Posts

Thats not really what I trying to do.

I have a list of them like

./files/pdf/something.pdf

./files/pdf/something1.pdf

./files/pdf/something2.pdf

./files/pdf/something3.pdf

and they are all set up in a variable called $files

and im trying to remove the ./files/pdf/ from everyone of them.

 

Link to comment
https://forums.phpfreaks.com/topic/133402-preg_replace-help/#findComment-693862
Share on other sites

Thats not really what I trying to do.

I have a list of them like

./files/pdf/something.pdf

./files/pdf/something1.pdf

./files/pdf/something2.pdf

./files/pdf/something3.pdf

and they are all set up in a variable called $files

and im trying to remove the ./files/pdf/ from everyone of them.

 

How about:

 

<?php
$files = array('./files/pdf/something.pdf',
'./files/pdf/something1.pdf',
'./files/pdf/something2.pdf',
'./files/pdf/something3.pdf');
$files = array_map(create_function('$x', 'return basename($x);'), $files);
print_r($files);

Link to comment
https://forums.phpfreaks.com/topic/133402-preg_replace-help/#findComment-693890
Share on other sites

Its closer but still not what I'm trying to do. Maybe I'm not explaining it right.

Here is what I'm doing.

I have a page set up where someone can go and select file they want.

It will zip the files and make a link that expires in 24 hours.

It then takes that link and emails it to them along with a list of files they requested.

I'm trying to get it to list the files in that email.

I have got it to list out the files like this.

./files/pdf/something.pdf

./files/pdf/something2.pdf

./files/pdf/something3.pdf

I just want to remove the

./files/pdf/

I have used preg_match to remove the . files and pdf but I still have the //.

If I know how to remove the // I would be set.

Maybe that will help a little.

 

Thanks

Junodixon

Link to comment
https://forums.phpfreaks.com/topic/133402-preg_replace-help/#findComment-694461
Share on other sites

The basename should do that for you. But another example would be:

 

<?php
    $filename = "./files/pdf/something.pdf";
    $filename = explode("/", $filename);
    $filename = $filename[count($filename)-1];
    echo $filename;
?>

 

As said above basename should do that without the fuss.

Link to comment
https://forums.phpfreaks.com/topic/133402-preg_replace-help/#findComment-694636
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.