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
sulen
Forum Commoner
Posts: 79 Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:
Post
by sulen » Tue Feb 07, 2006 6:44 pm
I want to replace the "\" with the "/" in a particular php string but cannot find a way to make it work for some reason. It will be greatly appreciated if someone could guide me. Thanks
I am using the following ways but it doesnt work
Code: Select all
$dir = ereg_replace('\', '/', $result[RequestResult][CourseDirPathName]);
I have even tried str_replace but to no use. Thanks
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Tue Feb 07, 2006 6:48 pm
this is with STR replace, should work
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Tue Feb 07, 2006 6:50 pm
what nickman said would work...do not use ereg_replace instead use preg_replace for complex regex replacements but for this, str_replace is faster.
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Tue Feb 07, 2006 6:51 pm
and i think it is much more easier.
sulen
Forum Commoner
Posts: 79 Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:
Post
by sulen » Tue Feb 07, 2006 6:52 pm
I tried the following code
Code: Select all
$dir = str_replace("\", "/", $result[RequestResult][CourseDirPathName]);
The error I get is Parse error: parse error in blah blah blah
Thanks
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Tue Feb 07, 2006 6:52 pm
post the exact error message...
sulen
Forum Commoner
Posts: 79 Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:
Post
by sulen » Tue Feb 07, 2006 6:53 pm
Parse error: parse error in /usr/local/apache/htdocs/homework/webserviceTest.php on line 69
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Tue Feb 07, 2006 6:54 pm
If you have the parse messsage it will be easier for us to solve the problem.
try using quotes around your string that you want to replace, like this
Code: Select all
$dir = str_replace("\", "/", "$result[RequestResult][CourseDirPathName]");
EDIT
Post lines 68 and 69 please.
sulen
Forum Commoner
Posts: 79 Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:
Post
by sulen » Tue Feb 07, 2006 6:56 pm
Dont worry got it to work.......... used this code
Code: Select all
$dir = ereg_replace('\\\\', '/', $result[RequestResult][CourseDirPathName]);
Thanks for all the help.
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Tue Feb 07, 2006 6:57 pm
Cool.
I see you used ereg replace, that is fine. I personally think STR_replace is much easier.
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Tue Feb 07, 2006 7:07 pm
sulen wrote: Dont worry got it to work.......... used this code
Code: Select all
$dir = ereg_replace('\\\\', '/', $result[RequestResult][CourseDirPathName]);
Thanks for all the help.
I could not understand...what these four slashes mean?
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Tue Feb 07, 2006 7:13 pm
LOL.
I was saying the same thing to myself.
sulen
Forum Commoner
Posts: 79 Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:
Post
by sulen » Tue Feb 07, 2006 7:15 pm
I am surprised too but it seemed to work with the four slashes instead of one. Funny thing.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Feb 07, 2006 7:28 pm
ahem
Code: Select all
$dir = str_replace('\\', '/', $string);