RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 5250 | Replies: 4 | Thread Tools  Display Modes
Reply
Join Date: Oct 2004
Location: San Francisco, CA
Posts: 338
Reputation: paradox814 is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
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: 338
Reputation: paradox814 is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: change backslash to foward slash

  #3  
Sep 6th, 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: 4
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.



Similar Threads
Other Threads in the PHP Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 8:14 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC