Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199908

Re: [PHP3] Hello... From: Rick Beebe (richard.beebe <email protected>)
Date: 08/25/99

8523543 wrote:
>
> Hello!
>
> I have a question...
> I would like to covert all backslash(\) to some other character in a string.
> How can I do?
> I have tried the following function:
> $string = ereg_replace("\\","*",$string);
> but it did not work.
> How should I express the backslash in PHP3 ?
> Thank you for your response!!
>
> Ken Tsai

You can use ereg_replace("\\\\","*",$string);

However, if there is more than one backslash in a row, you lose some of
them. I'm not sure why--I suspect it's part of the 'escaping' mechanism. For
example, the following script:

$string = "three\\\two\\one\zero";
$out = ereg_replace("\\\\","*",$string);

echo "$string\n$out\n";

Produces the following output:

three\\two\one\zero
three**two*one*zero

As you can see we lose a slash after three and two, and hence we also lose a
star. Four slashes also yields 2 while 5 yields 3.

If you're only changing single backslashes (such as in a DOS path), then you
shouldn't have any trouble.

-- 
  _______________________________________________________________________

Rick Beebe (203) 785-6416 Manager, Systems & Network Engineering FAX: (203) 785-3978 ITS-Med Client & Technology Services Richard.Beebe <email protected> Yale University School of Medicine P.O. Box 208078, New Haven, CT 06520-8078 _______________________________________________________________________

-- PHP 3 Mailing List <http://www.php.net/> To unsubscribe, send an empty message to php3-unsubscribe <email protected> To subscribe to the digest, e-mail: php3-digest-subscribe <email protected> To search the mailing list archive, go to: http://www.php.net/mailsearch.php3 To contact the list administrators, e-mail: php-list-admin <email protected>