Re: Double backslashes \\ in strings
- From: Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@xxxxxxxxxxxxxxxx>
- Date: Thu, 02 Oct 2008 09:40:52 +0200
JohnF schreef:
Erwin Moller < > wrote:JohnF schreef:An analogous problem would be: suppose you want to echo two backslashes; you'd have to use the statement echo '\\\\'; with four backslashes instead. Now, I can see why you have to type echo "\\\\"; since escaped chars are translated inside "double quotes". But they're not translated inside 'single quotes', so why can't you type echo '\\'; to get \\? Maybe it's still vague why I seem so lazy thatErwin Moller < > wrote:Well, the problem is still a little vague to me.JohnF schreef:Thanks, Erwin. I only mentioned preg_replace becauseI have a function textag($expression){...}Nobody mentioned preg_replace. ;-)
whose $expression argument is a string that
can contain substrings like \alpha with one
backslash or like a&b\\c&d with two backslashes.
If I write <?php textag('\alpha'); ?> with the
expression argument in single quotes, then that
works fine, and the single backslash isn't
interpreted or changed, which is what I want.
But if I write <?php textag('a&b\\c&d'); ?>
then the double \\ gets translated to a single \,
which isn't what I want. Now, I can write
<?php textag('a&b\\\\c&d'); ?> to get a&b\\c&d,
but that's quit inconvenient and kludgey.
Is there some way to fix this that's transparent
to the user calling textag()? I can't really
do any kind of preg_replace, because that would
also change the originally correct \alpha to
incorrect \\alpha. Thanks for any suggestions,
Read up here:
http://www.php.net/manual/en/language.types.string.php
it had crossed my mind, but then I realized that would
be barking up the wrong tree.
I don't want to type a few extra backslashes. That's
because the real problem is that users will be typing
these strings, not to echo them, but as arguments to
a function like <?php textag('a\\b'); ?> where
the letter a is followed by two \\ backslashes
(not one \) and then followed by the letter b.
Users will not expect to need to type four
backslashes when they want two, and that's liable
to cause problems I'd rather avoid.
Did you read my response?
Did you follow and read the links I sent you?
Did you understand it all?
All your confusion and problems are unneeded, nor is it needed for the users to type 4 slashes if they want 2.
Please reread my last posting and make sure you understand everything.
Regards,
Erwin Moller
--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why? http://improve-usenet.org/
============================
.
- Prev by Date: Re: fonts
- Next by Date: Re: fonts
- Previous by thread: fonts
- Next by thread: List predefined variables
- Index(es):
Relevant Pages
|