473,503 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Backslash confusion

I have to pass the string '\abcd' to a function. Ofcourse one (or two) extra
'\' is needed to escape but experimenting with it shows that I have to pass
three extra backslashes to make it work.

<script>
var q = "\\\\abcd";
displayLatex(q);
</script>
/* this function is in another file */

function displayLatex(q) {
alert(q); /* this shows \abcd when called by above script*/

}
Can anyone explain why this is so? why 4 backslashes?
Jun 27 '08 #1
4 1356
freelance71 schreef:
I have to pass the string '\abcd' to a function. Ofcourse one (or two) extra
'\' is needed to escape but experimenting with it shows that I have to pass
three extra backslashes to make it work.

<script>
var q = "\\\\abcd";
displayLatex(q);
</script>
/* this function is in another file */

function displayLatex(q) {
alert(q); /* this shows \abcd when called by above script*/

}
Can anyone explain why this is so? why 4 backslashes?

I do not understand.
Your script alerts \\abcd over here (on FF), as expected.
There must be more to it than you describe.

Regards,
Erwin Moller
Jun 27 '08 #2

"Erwin Moller"
<Si******************************************@spam yourself.comwrote in
message news:48***********************@news.xs4all.nl...
freelance71 schreef:
>I have to pass the string '\abcd' to a function. Ofcourse one (or two)
extra '\' is needed to escape but experimenting with it shows that I have
to pass three extra backslashes to make it work.

<script>
var q = "\\\\abcd";
displayLatex(q);
</script>
/* this function is in another file */

function displayLatex(q) {
alert(q); /* this shows \abcd when called by above script*/

}
Can anyone explain why this is so? why 4 backslashes?

I do not understand.
Your script alerts \\abcd over here (on FF), as expected.
There must be more to it than you describe.

Regards,
Erwin Moller

can it be because I'm using it in a PHP file like this?

<?php

echo <<< HTMLOUT

<script>

var q = '\\\\abcd';

displayLatex(q);

</script>

HTMLOUT;

?>
Jun 27 '08 #3
freelance71 schreef:
"Erwin Moller"
<Si******************************************@spam yourself.comwrote in
message news:48***********************@news.xs4all.nl...
>freelance71 schreef:
>>I have to pass the string '\abcd' to a function. Ofcourse one (or two)
extra '\' is needed to escape but experimenting with it shows that I have
to pass three extra backslashes to make it work.

<script>
var q = "\\\\abcd";
displayLatex(q);
</script>
/* this function is in another file */

function displayLatex(q) {
alert(q); /* this shows \abcd when called by above script*/

}
Can anyone explain why this is so? why 4 backslashes?
I do not understand.
Your script alerts \\abcd over here (on FF), as expected.
There must be more to it than you describe.

Regards,
Erwin Moller


can it be because I'm using it in a PHP file like this?
Yes. That is the reason.
>
<?php

echo <<< HTMLOUT

<script>

var q = '\\\\abcd';
that becomes:
var q = '\\abcd';

in your HTML.
Simply check your source in your browser to see it.

Regards,
Erwin Moller
>
displayLatex(q);

</script>

HTMLOUT;

?>

Jun 27 '08 #4
freelance71 wrote:
>freelance71 schreef:
>>I have to pass the string '\abcd' to a function. Ofcourse one (or two)
extra '\' is needed to escape but experimenting with it shows that I have
to pass three extra backslashes to make it work.
[...]
can it be because I'm using it in a PHP file like this?

<?php

echo <<< HTMLOUT

<script>

var q = '\\\\abcd';

displayLatex(q);

</script>

HTMLOUT;

?>
Yes, you have to escape each backslash for use with `echo'. A simple test
(with php -a) shows that

<?php

echo <<<HTML

var q = '\\a';

HTML;

?>

displays only one backslash.

The simple and most efficient solution is to take heed of this general
advice: Do not let the PHP parser do things it does not have to.

<?php
...
?>
var q = '\\a';
<?php
...
?>

(The first and last part are optional, of course.)
F'up2 cl.php

PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6887
by: Aloysio Figueiredo | last post by:
I need to replace every ocurrence of '/' in s by '\/' in order to create a file named s. My first attempt was: s = '\/'.join(s.split('/')) but it doesn't work: >>> s = 'a/b' >>> s =...
3
22215
by: Terry Asher | last post by:
The following script does NOT escape the Apostrophe. Meaning when you mouseover the image the Alt tag says this: DMACC, It and then it stops. <SCRIPT Language="JavaScript"> var pos = "DMACC,...
19
6290
by: Alan J. Flavell | last post by:
The story so far: on somewhat unrelated newsgroup, my attention fell upon the URL: http://www.speedtouchdsl.com/prod706.htm which contains a link to the purported URL:...
2
3227
by: John Dann | last post by:
I guess there must be some convention or Windows specification for whether the backslash immediately preceding the file name in a full path string to a file is formally part of the path string or...
3
22954
by: Stef Mientki | last post by:
It looks like sometimes a single backslash is replaced by a double backslash, but sometimes it's not ??? See the error message below, the first backslash is somewhere (not explicitly in my code)...
2
2151
by: Tobiah | last post by:
>>"'" "'" "'" "\\'" "\\'" This is quite different than any other language that I am used to. Normally, a double backslash takes away the special meaning of the last backslash, and so you...
5
15642
by: vlsidesign | last post by:
The printf function returns "warning: unknown escape sequence: \040" for a backslash-space combination. If the ascii decimal number for space is 32 and the backslash is 92, why this particular...
4
2266
by: Razzbar | last post by:
I'm working on a bookmarklet that grabs information from a page and submits it to a server. Yet another social bookmarking application. I'm having trouble with page titles that include an...
4
3603
nithinpes
by: nithinpes | last post by:
I will boil down my exact requirement to this: I should print out lines that do not contain semi-colon, backslash and closing parentheses. The following one -liner works fine. perl -ne "unless(//)...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.