Replace all forward slashes with backward slashes

Hello.

This:

        $txtName = ereg_replace ('\\', '/', $txtName);

is giving me the following warning:
 
     Warning: ereg_replace(): REG_EESCAPE in /home/scipts/test.php


How can I replace all forward slashes ( \ ) with backward slashes ( / )  ????

Thanks!
LVL 16
hankknightAsked:
Who is Participating?
 
hernst42Connect With a Mentor Commented:
why don't you use
$txtName = str_replace('\\', '/', $txtName)
for that purpose?
0
 
hernst42Commented:
If you want to do it with ereg_replace use
$txtName = ereg_replace ('\\\\', '/', $txtName);

It's because the \\ will be turned to \ for the argument of the ereg_replace and as the \ is a special charachter it needs to be escaped also. So you need that 4 backslahes to simulate one real backslash in your string.
0
All Courses

From novice to tech pro — start learning today.