Page 1 of 1

Code to ignore/remove spaces in filenames/paths

Posted: Wed Jan 21, 2004 5:44 am
by drummo
I am looking for a piece of code that will ignore the spaces in file paths and file names.
I have a variable ($longName) that holds a path (C:/Program Files/file 2.doc)

When I want to create a link for the path, it falls over at the space. Any ideas would be great.

Posted: Wed Jan 21, 2004 5:59 am
by DuFF
Just use:

Code: Select all

<?php
$link = "C:/Program Files/file 2.doc";
$newlink = str_replace(" ", "%20", $link);
?>
This should output: "C:/Program%20Files/file%202.doc" which should work in a link

Posted: Wed Jan 21, 2004 7:14 am
by patrikG
Also, have a look at [php_man]urlencode[/php_man] and [php_man]htmlentities[/php_man].

Posted: Thu Jan 22, 2004 3:23 pm
by drummo
Thanks guys...much appreciated