tags:

views:

760

answers:

5

I have a directory with PDF files that I need to create an index for. It is a PHP page with a list of links:

<A HREF="path to file">filename</A>

The filenames can be complicated:

LVD 2-1133 - Ändring av dumpningslina (1984-11-20).pdf

What is the correct way to link to this file on a Linux/Apache server?

Is there a PHP function to do this conversion?

A: 

urlencode() should probably do what you want.

Edit: urlencode() works fine on swedish characters.


    <?php
        echo urlencode("åäö");   
    ?>

converts to:


    %E5%E4%F6
Andy
A: 

URL encoding. I think it's urlencode() in PHP.

Anders Sandvig
+3  A: 

You can use rawurlencode() to convert a string according to the RFC 1738 spec. This function replaces all non-alphanumeric characters by their associated code.

The difference with urlencode() is that spaces are encoded as plus signs.

You'll probably want to use the last one.

This technique is called Percent or URL encoding. See Wikipedia for more details.

Javache
A: 

rawurlencode will encode "exotic" characters in a URL.

Rob
+1  A: 

The urlencode() function will convert spaces into plus signs (+), so it won't work. The rawurlencode does the trick. Thanks.

Be sure to convert each part of the path separately, otherwise path/file will be converted into path%2Ffile. (which was what I missed)

Peter Olsson