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/26/99

Sorry, I don't know what GIGO means.

bls wrote:
>
> GIGO, dude ;)
>
> <?php
> $foo = "three\\\two\\one\zero";
> $bar = 'three\\\two\\one\zero';
> echo (($foo == $bar) ? "SAME" : "DIFFERENT") . "<br>\n";
> printf("foo is %s chars, but bar is %s<br>\n",
> strlen($foo), strlen($bar));
> ?>
>
> $foo actually has a tab character in it, I believe...
> Anyways, I would prefer this:
>
> $out = strtr($bar, '\\', '*'); # it's quicker too.

I don't see any difference between single and double quotes on my machine.
Your script echos "SAME". I did try them both before I sent the below
message. I also wasn't using \\\two in my original test. I chose that as a
better illustration. I just switched to \\\pwo (\p isn't anything is it?)
with the same result.

I didn't know about strtr. Thanks. But it doesn't make any difference. My
test script below runs identically. I was running the test interactively--my
php.cgi is version 3.0.7. Just for chuckles, I just ran it through the web
server which is running mod_php 3.0.12. Same results.

--Rick

 
> -- Blair
>
> // 3NET SOLUTIONS NZ
> // Web: http://www.3net.co.nz/
> // Mail: P.O Box 14-151 Kilbirnie, Wgtn NZ
> // Phone: +64-04-387-9010 (Voice)
>
> Original message from: Rick Beebe
> >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>