Solved

Replace all forward slashes with backward slashes

Posted on 2004-10-21
2,576 Views
Last Modified: 2012-08-14
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!
0
Question by:hankknight
    2 Comments
     
    LVL 48

    Accepted Solution

    by:
    why don't you use
    $txtName = str_replace('\\', '/', $txtName)
    for that purpose?
    0
     
    LVL 48

    Expert Comment

    by:hernst42
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    The viewer will learn how to count occurrences of each item in an array.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now