Page 1 of 1
string replace issue
Posted: Tue Feb 07, 2006 6:44 pm
by sulen
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
Posted: Tue Feb 07, 2006 6:48 pm
by nickman013
this is with STR replace, should work
Posted: Tue Feb 07, 2006 6:50 pm
by raghavan20
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.
Posted: Tue Feb 07, 2006 6:51 pm
by nickman013
and i think it is much more easier.
Posted: Tue Feb 07, 2006 6:52 pm
by sulen
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
Posted: Tue Feb 07, 2006 6:52 pm
by raghavan20
post the exact error message...
Posted: Tue Feb 07, 2006 6:53 pm
by sulen
Parse error: parse error in /usr/local/apache/htdocs/homework/webserviceTest.php on line 69
Posted: Tue Feb 07, 2006 6:54 pm
by nickman013
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.
Posted: Tue Feb 07, 2006 6:56 pm
by sulen
Dont worry got it to work.......... used this code
Code: Select all
$dir = ereg_replace('\\\\', '/', $result[RequestResult][CourseDirPathName]);
Thanks for all the help.
Posted: Tue Feb 07, 2006 6:57 pm
by nickman013
Cool.
I see you used ereg replace, that is fine. I personally think STR_replace is much easier.
Posted: Tue Feb 07, 2006 7:07 pm
by raghavan20
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?
Posted: Tue Feb 07, 2006 7:13 pm
by nickman013
LOL.
I was saying the same thing to myself.
Posted: Tue Feb 07, 2006 7:15 pm
by sulen
I am surprised too but it seemed to work with the four slashes instead of one. Funny thing.
Posted: Tue Feb 07, 2006 7:28 pm
by feyd
ahem
Code: Select all
$dir = str_replace('\\', '/', $string);