User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,596 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,679 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 4398 | Replies: 4
Reply
Join Date: Oct 2004
Location: San Francisco, CA
Posts: 337
Reputation: paradox814 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

change backslash to foward slash

  #1  
Sep 5th, 2005
how do I reverse the direction of a slash? I am trying to reverse the slashes in the directory path of a windows system.

I have tried so many things but then when I actually test it to make sure it works, it always fails, so I decided to try it via brute force. Again this fails because of special symbols, take for example:

[PHP]for ($i=0; $i<strlen($file_dir); $i++)
{
if ($file_dir{$i} == "\\")
{
$file_dir{$i} = "/";
}
}[/PHP]

when I finally tried this method it works wonderfully until I hit some special cases like when I have a folder called:
C:\temp\2004
it turns it into (a tab and some weird symbol in there):
C: emp€4
but I really want it to look like:
C:/temp/2004
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2005
Location: Sheffield, UK
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: change backslash to foward slash

  #2  
Sep 5th, 2005
You may want to use addslashes and stripslashes functions.
For example: $file_dir = addsashes($file_dir);
so you will now get symbols (\t is tab, \n is new line etc)

You may try str_replace function to change the direction of the slashes.
.
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote  
Join Date: Oct 2004
Location: San Francisco, CA
Posts: 337
Reputation: paradox814 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: change backslash to foward slash

  #3  
Sep 5th, 2005
all that does is add an escape slash, I didn't want to do that at all. I want to reverse the direction of the slash. I already know about addslashes/stripslashes and magic_quotes and all that jazz... I want to be able to reverse the direction of the slash
Reply With Quote  
Join Date: Jan 2005
Location: Sheffield, UK
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: change backslash to foward slash

  #4  
Sep 6th, 2005
Then str_replace function is the solution... I guess
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote  
Join Date: Aug 2005
Posts: 76
Reputation: leelee is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
leelee leelee is offline Offline
Junior Poster in Training

Re: change backslash to foward slash

  #5  
Sep 9th, 2005
try this:

$newphrase = str_replace('\\', '/', $phrase);
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:35 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC