Code to ignore/remove spaces in filenames/paths

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
drummo
Forum Newbie
Posts: 5
Joined: Wed Jan 21, 2004 5:44 am

Code to ignore/remove spaces in filenames/paths

Post 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.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Also, have a look at [php_man]urlencode[/php_man] and [php_man]htmlentities[/php_man].
drummo
Forum Newbie
Posts: 5
Joined: Wed Jan 21, 2004 5:44 am

Post by drummo »

Thanks guys...much appreciated
Post Reply