By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

replace single slash with double slash

P: n/a
I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:

<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>

Code above produces the following error:

Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
\pages\replace.php on line 12

In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf

but it seems to be very difficult replacing slashes.

Any help would be greatly appreciated

Sep 22 '07 #1
Share this Question
Share on Google+
23 Replies


P: n/a
dk*******@yahoo.com wrote:
I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:

<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>

Code above produces the following error:

Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
\pages\replace.php on line 12

In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf

but it seems to be very difficult replacing slashes.

Any help would be greatly appreciated
Why go to all that trouble? str_replace is much easier and faster.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 22 '07 #2

P: n/a
On Sep 21, 9:32 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
dkirkd...@yahoo.com wrote:
I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>
Code above produces the following error:
Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
\pages\replace.php on line 12
In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf
but it seems to be very difficult replacing slashes.
Any help would be greatly appreciated

Why go to all that trouble? str_replace is much easier and faster.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
tried:

<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = str_replace("\\", "\\\\", "$var");
?>

and received:

\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf

Sep 22 '07 #3

P: n/a
dk*******@yahoo.com wrote:
On Sep 21, 9:32 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>dkirkd...@yahoo.com wrote:
>>I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>
Code above produces the following error:
Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
\pages\replace.php on line 12
In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf
but it seems to be very difficult replacing slashes.
Any help would be greatly appreciated
Why go to all that trouble? str_replace is much easier and faster.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

tried:

<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = str_replace("\\", "\\\\", "$var");
?>

and received:

\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf
First of all,

$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";

isn't really valid. The backslash character is the escape character.
In this case all but the last one have a non-escapable character after
them, so PHP just puts out the slash. However, if you had something like:

$var = "\\wusais\nbad\tworse";

The \n would be taken as a newline character and \t as a tab character.
And in the case of your last backslash, the \00505882 is taken as a
character with numberic value '005' (in octal), followed by 05882.

To get good output, you need to start with good input. Then something like:

Where is your string coming from? Are you actually defining it like
that? If so, it's invalid.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 22 '07 #4

P: n/a

"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:qf******************************@comcast.com. ..
dk*******@yahoo.com wrote:
>On Sep 21, 9:32 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>>dkirkd...@yahoo.com wrote:
I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>
Code above produces the following error:
Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
\pages\replace.php on line 12
In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf
but it seems to be very difficult replacing slashes.
Any help would be greatly appreciated
Why go to all that trouble? str_replace is much easier and faster.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

tried:

<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = str_replace("\\", "\\\\", "$var");
?>

and received:

\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf

First of all,

$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";

isn't really valid. The backslash character is the escape character. In
this case all but the last one have a non-escapable character after them,
so PHP just puts out the slash. However, if you had something like:

$var = "\\wusais\nbad\tworse";

The \n would be taken as a newline character and \t as a tab character.
And in the case of your last backslash, the \00505882 is taken as a
character with numberic value '005' (in octal), followed by 05882.

To get good output, you need to start with good input. Then something
like:

Where is your string coming from? Are you actually defining it like that?
If so, it's invalid.
i'm not sure what an invalid string looks like, however you are explaining
his results accurately.

depending on the environment, which is (almost) safely assumed as windows,
php does it's own converting of the slashes. so, a unc like this
\\server\share\resource is interpreted exactly the same as
//server/share/resource...on windows. here's an easy fix...
$var = '\\server\share\resource';

no need to do a replace and no need to worry about escape characters. in
php, what is inside quotes is parsed where an indication is given that
parsing should be done. jerry describes some of them above. tics (single
quotes) let php know that no parsing of the string should be performed.

if you have control over the creating of that path, just use forward-slashes
and all will be well, and os independent. if you don't, then php will
already treat the string properly (as in, you retrieve the path from a
database query). i don't need to mention that if you have control of the
string and are using double quotes and backslashes, what those results will
get you. jerry explained that already.

cheers.
Sep 22 '07 #5

P: n/a
dk*******@yahoo.com wrote:
I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:

<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>

Code above produces the following error:

Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
\pages\replace.php on line 12

In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf

but it seems to be very difficult replacing slashes.

Any help would be greatly appreciated
$var = "\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig \\00505882.pdf";

echo strtr($var, array('\\' ='\\\\'));

note that initially $var actually contains only single slashes, however
you must write each slash twice because of php escaping rules.

--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Sep 22 '07 #6

P: n/a
On Sep 22, 4:28 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>
Code above produces the following error:
Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
\pages\replace.php on line 12
In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf
but it seems to be very difficult replacing slashes.
Any help would be greatly appreciated

$var = "\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig \\00505882.pdf";

echo strtr($var, array('\\' ='\\\\'));

note that initially $var actually contains only single slashes, however
you must write each slash twice because of php escaping rules.

--
gosha bine

extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok- Hide quoted text -

- Show quoted text -
These file paths are coming from a database, they are all windows
paths and they reside on a company intranet so it is a "controlled"
environment. Every file path is structured just like \\wusais\Intranets
\Intranets\fpdb\pdf\weinig\00505882.pdf. For what I am trying to do, I
have to double up on all of the slashes which is really being a pain.
At this point, I believe I am going to try and explode the string to
remove all the slashes and then reassemble it with the correct number
of slashes.

Sep 22 '07 #7

P: n/a
dk*******@yahoo.com wrote:
On Sep 22, 4:28 am, gosha bine <stereof...@gmail.comwrote:
>dkirkd...@yahoo.com wrote:
>>I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>
Code above produces the following error:
Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
\pages\replace.php on line 12
In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf
but it seems to be very difficult replacing slashes.
Any help would be greatly appreciated
$var = "\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig \\00505882.pdf";

echo strtr($var, array('\\' ='\\\\'));

note that initially $var actually contains only single slashes, however
you must write each slash twice because of php escaping rules.

--
gosha bine

extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok- Hide quoted text -

- Show quoted text -

These file paths are coming from a database, they are all windows
paths and they reside on a company intranet so it is a "controlled"
environment. Every file path is structured just like \\wusais\Intranets
\Intranets\fpdb\pdf\weinig\00505882.pdf. For what I am trying to do, I
have to double up on all of the slashes which is really being a pain.
At this point, I believe I am going to try and explode the string to
remove all the slashes and then reassemble it with the correct number
of slashes.
That is MUCH DIFFERENT than saying:

$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";

When it comes from a database, PHP will automatically escape the slashes
for you.

<?
$var = "\\\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\wein ig\\00505882.pdf";
echo $var , "\n";
$new = str_replace('\\', '\\\\', $var);
echo $new;
?>

Output:

\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505 882.pdf
\\\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weini g\\00505882.pdf
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 22 '07 #8

P: n/a
dk*******@yahoo.com wrote:
On Sep 22, 4:28 am, gosha bine <stereof...@gmail.comwrote:
>dkirkd...@yahoo.com wrote:
>>I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>
Code above produces the following error:
Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
\pages\replace.php on line 12
In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf
but it seems to be very difficult replacing slashes.
Any help would be greatly appreciated
$var = "\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig \\00505882.pdf";

echo strtr($var, array('\\' ='\\\\'));

note that initially $var actually contains only single slashes, however
you must write each slash twice because of php escaping rules.

--
gosha bine

extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok- Hide quoted text -

- Show quoted text -

These file paths are coming from a database, they are all windows
paths and they reside on a company intranet so it is a "controlled"
environment. Every file path is structured just like \\wusais\Intranets
\Intranets\fpdb\pdf\weinig\00505882.pdf. For what I am trying to do, I
have to double up on all of the slashes which is really being a pain.
At this point, I believe I am going to try and explode the string to
remove all the slashes and then reassemble it with the correct number
of slashes.
This doesn't matter where the string comes from. The code I posted above

$var = strtr($var, array('\\' ='\\\\'));

should work for the strings coming from the database as well.


--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Sep 22 '07 #9

P: n/a
On Sep 22, 10:40 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
On Sep 22, 4:28 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>
Code above produces the following error:
Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
\pages\replace.php on line 12
In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf
but it seems to be very difficult replacing slashes.
Any help would be greatly appreciated
$var = "\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig \\00505882.pdf";
echo strtr($var, array('\\' ='\\\\'));
note that initially $var actually contains only single slashes, however
you must write each slash twice because of php escaping rules.
--
gosha bine
extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok-Hide quoted text -
- Show quoted text -
These file paths are coming from a database, they are all windows
paths and they reside on a company intranet so it is a "controlled"
environment. Every file path is structured just like \\wusais\Intranets
\Intranets\fpdb\pdf\weinig\00505882.pdf. For what I am trying to do, I
have to double up on all of the slashes which is really being a pain.
At this point, I believe I am going to try and explode the string to
remove all the slashes and then reassemble it with the correct number
of slashes.

This doesn't matter where the string comes from. The code I posted above

$var = strtr($var, array('\\' ='\\\\'));

should work for the strings coming from the database as well.

--
gosha bine

extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok- Hide quoted text -

- Show quoted text -
the code:

<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>

produces this:

\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf

close but the end is still killing me...

Sep 22 '07 #10

P: n/a
dk*******@yahoo.com wrote:
On Sep 22, 10:40 am, gosha bine <stereof...@gmail.comwrote:
>dkirkd...@yahoo.com wrote:
>>On Sep 22, 4:28 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>
Code above produces the following error:
Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
\pages\replace.php on line 12
In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf
but it seems to be very difficult replacing slashes.
Any help would be greatly appreciated
$var = "\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig \\00505882.pdf";
echo strtr($var, array('\\' ='\\\\'));
note that initially $var actually contains only single slashes, however
you must write each slash twice because of php escaping rules.
--
gosha bine
extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok-Hide quoted text -
- Show quoted text -
These file paths are coming from a database, they are all windows
paths and they reside on a company intranet so it is a "controlled"
environment. Every file path is structured just like \\wusais\Intranets
\Intranets\fpdb\pdf\weinig\00505882.pdf. For what I am trying to do, I
have to double up on all of the slashes which is really being a pain.
At this point, I believe I am going to try and explode the string to
remove all the slashes and then reassemble it with the correct number
of slashes.
This doesn't matter where the string comes from. The code I posted above

$var = strtr($var, array('\\' ='\\\\'));

should work for the strings coming from the database as well.

--
gosha bine

extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok- Hide quoted text -

- Show quoted text -

the code:

<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>

produces this:

\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf

close but the end is still killing me...
That's because your starting string is NOT VALID! See my post above.

Get the string from the database and try parsing it. You'll get a much
different result.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 22 '07 #11

P: n/a
On Sep 22, 11:29 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
dkirkd...@yahoo.com wrote:
On Sep 22, 10:40 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
On Sep 22, 4:28 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>
Code above produces the following error:
Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
\pages\replace.php on line 12
In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf
but it seems to be very difficult replacing slashes.
Any help would be greatly appreciated
$var = "\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig \\00505882.pdf";
echo strtr($var, array('\\' ='\\\\'));
note that initially $var actually contains only single slashes, however
you must write each slash twice because of php escaping rules.
--
gosha bine
extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok-Hidequoted text -
- Show quoted text -
These file paths are coming from a database, they are all windows
paths and they reside on a company intranet so it is a "controlled"
environment. Every file path is structured just like \\wusais\Intranets
\Intranets\fpdb\pdf\weinig\00505882.pdf. For what I am trying to do, I
have to double up on all of the slashes which is really being a pain.
At this point, I believe I am going to try and explode the string to
remove all the slashes and then reassemble it with the correct number
of slashes.
This doesn't matter where the string comes from. The code I posted above
$var = strtr($var, array('\\' ='\\\\'));
should work for the strings coming from the database as well.
--
gosha bine
extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok-Hide quoted text -
- Show quoted text -
the code:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>
produces this:
\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf
close but the end is still killing me...

That's because your starting string is NOT VALID! See my post above.

Get the string from the database and try parsing it. You'll get a much
different result.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
My problem is that the string coming from the database as variable
with 2 slashes in the front and 1 slash between each directory. Once
the variable comes from the db, I am passing it on to a javascript. If
I pass the variable as is, the script will not work but if I double up
on the slashes everything works fine. So, I have to take the file path
that is coming out of the db and double up on the slashes. Using only
php, everything works fine with the slashes the way they are.

Sep 22 '07 #12

P: n/a

"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:U6******************************@comcast.com. ..
dk*******@yahoo.com wrote:
>On Sep 22, 10:40 am, gosha bine <stereof...@gmail.comwrote:
>>dkirkd...@yahoo.com wrote:
On Sep 22, 4:28 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
>I am having a bit of trouble trying to double up on slashes in a file
>path. What I am trying to do is very similar to the code below:
><?
>$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
>$new = preg_replace("\\", "\\\", "$var");
>?>
>Code above produces the following error:
>Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
>\pages\replace.php on line 12
>In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
>\pdf\\weinig\\00505882.pdf
>but it seems to be very difficult replacing slashes.
>Any help would be greatly appreciated
$var =
"\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\we inig\\00505882.pdf";
echo strtr($var, array('\\' ='\\\\'));
note that initially $var actually contains only single slashes,
however
you must write each slash twice because of php escaping rules.
--
gosha bine
extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok-Hide quoted text -
- Show quoted text -
These file paths are coming from a database, they are all windows
paths and they reside on a company intranet so it is a "controlled"
environment. Every file path is structured just like \\wusais\Intranets
\Intranets\fpdb\pdf\weinig\00505882.pdf. For what I am trying to do, I
have to double up on all of the slashes which is really being a pain.
At this point, I believe I am going to try and explode the string to
remove all the slashes and then reassemble it with the correct number
of slashes.
This doesn't matter where the string comes from. The code I posted above

$var = strtr($var, array('\\' ='\\\\'));

should work for the strings coming from the database as well.

--
gosha bine

extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok- Hide quoted text -

- Show quoted text -

the code:

<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>

produces this:

\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf

close but the end is still killing me...

That's because your starting string is NOT VALID! See my post above.
NO SUCH THING AS AN INVALID STRING. his problem is understanding the
unexpected results. you already explained that to him, it just seems he's
still lost.
Get the string from the database and try parsing it. You'll get a much
different result.
php doesn't parse strings whenever it feels like it. the only reason you
have to escape strings *you* create in php is because you have the ability
to put variables in the strings and use octal,hex, and other special
character notation in the string...some of which you cannot use the keyboard
to produce in any other way. but, that's only when YOU are creating them.

if your path is coming from a db, php doesn't care what data type a field
is. if you assign a db field's value to a variable, php just assigns it.
this is quite different than you saying literally that $var = "some
$stringVariable". and that is interpreted differently than $var = 'some
$stringVariable'. one is parsed, the other, literal.
Sep 22 '07 #13

P: n/a

<dk*******@yahoo.comwrote in message
news:11*********************@o80g2000hse.googlegro ups.com...
On Sep 22, 11:29 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>dkirkd...@yahoo.com wrote:
On Sep 22, 10:40 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
On Sep 22, 4:28 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
I am having a bit of trouble trying to double up on slashes in a
file
path. What I am trying to do is very similar to the code below:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>
Code above produces the following error:
Parse error: parse error, unexpected T_VARIABLE in
c:\Inetpub\wwwroot
\pages\replace.php on line 12
In the end, $new needs to be:
\\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf
but it seems to be very difficult replacing slashes.
Any help would be greatly appreciated
$var =
"\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\wei nig\\00505882.pdf";
echo strtr($var, array('\\' ='\\\\'));
note that initially $var actually contains only single slashes,
however
you must write each slash twice because of php escaping rules.
--
gosha bine
extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok-Hidequoted text -
- Show quoted text -
These file paths are coming from a database, they are all windows
paths and they reside on a company intranet so it is a "controlled"
environment. Every file path is structured just like
\\wusais\Intranets
\Intranets\fpdb\pdf\weinig\00505882.pdf. For what I am trying to do,
I
have to double up on all of the slashes which is really being a pain.
At this point, I believe I am going to try and explode the string to
remove all the slashes and then reassemble it with the correct number
of slashes.
This doesn't matter where the string comes from. The code I posted
above
>$var = strtr($var, array('\\' ='\\\\'));
>should work for the strings coming from the database as well.
>--
gosha bine
>extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok-Hide quoted text -
>- Show quoted text -
the code:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>
produces this:
\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf
close but the end is still killing me...

That's because your starting string is NOT VALID! See my post above.

Get the string from the database and try parsing it. You'll get a much
different result.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

My problem is that the string coming from the database as variable
with 2 slashes in the front and 1 slash between each directory. Once
the variable comes from the db, I am passing it on to a javascript. If
I pass the variable as is, the script will not work but if I double up
on the slashes everything works fine. So, I have to take the file path
that is coming out of the db and double up on the slashes. Using only
php, everything works fine with the slashes the way they are.

gotcha...it's just hard to express for the purposes of posting here what
jerry would consider a *valid* string (whatever that means), so that we have
something to work with. is that about right?
Sep 22 '07 #14

P: n/a
On Sep 22, 2:43 pm, "Steve" <no....@example.comwrote:
<dkirkd...@yahoo.comwrote in message

news:11*********************@o80g2000hse.googlegro ups.com...


On Sep 22, 11:29 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
dkirkd...@yahoo.com wrote:
On Sep 22, 10:40 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
On Sep 22, 4:28 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
I am having a bit of trouble trying to double up on slashes in a
file
path. What I am trying to do is very similar to the code below:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>
Code above produces the following error:
Parse error: parse error, unexpected T_VARIABLE in
c:\Inetpub\wwwroot
\pages\replace.php on line 12
In the end, $new needs to be:
\\\\wusais\\Intranets\\Intranets\\fpdb\
\pdf\\weinig\\00505882.pdf
but it seems to be very difficult replacing slashes.
Any help would be greatly appreciated
$var =
"\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\wein ig\\00505882.pdf";
echo strtr($var, array('\\' ='\\\\'));
note that initially $var actually contains only single slashes,
however
you must write each slash twice because of php escaping rules.
--
gosha bine
extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok-Hidequotedtext -
- Show quoted text -
These file paths are coming from a database, they are all windows
paths and they reside on a company intranet so it is a "controlled"
environment. Every file path is structured just like
\\wusais\Intranets
\Intranets\fpdb\pdf\weinig\00505882.pdf. For what I am trying to do,
I
have to double up on all of the slashes which is really being a pain.
At this point, I believe I am going to try and explode the string to
remove all the slashes and then reassemble it with the correct number
of slashes.
This doesn't matter where the string comes from. The code I posted
above
$var = strtr($var, array('\\' ='\\\\'));
should work for the strings coming from the database as well.
--
gosha bine
extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok-Hidequoted text -
- Show quoted text -
the code:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>
produces this:
\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf
close but the end is still killing me...
That's because your starting string is NOT VALID! See my post above.
Get the string from the database and try parsing it. You'll get a much
different result.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
My problem is that the string coming from the database as variable
with 2 slashes in the front and 1 slash between each directory. Once
the variable comes from the db, I am passing it on to a javascript. If
I pass the variable as is, the script will not work but if I double up
on the slashes everything works fine. So, I have to take the file path
that is coming out of the db and double up on the slashes. Using only
php, everything works fine with the slashes the way they are.

gotcha...it's just hard to express for the purposes of posting here what
jerry would consider a *valid* string (whatever that means), so that we have
something to work with. is that about right?- Hide quoted text -

- Show quoted text -
I still have not figured out a way to turn this:

$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";

into this using php:

$var = "\\\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\wein ig\
\00505882.pdf";

Sep 22 '07 #15

P: n/a
Steve wrote:
<dk*******@yahoo.comwrote in message
news:11*********************@o80g2000hse.googlegro ups.com...
>On Sep 22, 11:29 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>>dkirkd...@yahoo.com wrote:
On Sep 22, 10:40 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
>On Sep 22, 4:28 am, gosha bine <stereof...@gmail.comwrote:
>>dkirkd...@yahoo.com wrote:
>>>I am having a bit of trouble trying to double up on slashes in a
>>>file
>>>path. What I am trying to do is very similar to the code below:
>>><?
>>>$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
>>>$new = preg_replace("\\", "\\\", "$var");
>>>?>
>>>Code above produces the following error:
>>>Parse error: parse error, unexpected T_VARIABLE in
>>>c:\Inetpub\wwwroot
>>>\pages\replace.php on line 12
>>>In the end, $new needs to be:
>>>\\\\wusais\\Intranets\\Intranets\\fpdb\
>>>\pdf\\weinig\\00505882.pdf
>>>but it seems to be very difficult replacing slashes.
>>>Any help would be greatly appreciated
>>$var =
>>"\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\ weinig\\00505882.pdf";
>>echo strtr($var, array('\\' ='\\\\'));
>>note that initially $var actually contains only single slashes,
>>however
>>you must write each slash twice because of php escaping rules.
>>--
>>gosha bine
>>extended php parser ~http://code.google.com/p/pihipi
>>blok ~http://www.tagarga.com/blok-Hidequoted text -
>>- Show quoted text -
>These file paths are coming from a database, they are all windows
>paths and they reside on a company intranet so it is a "controlled"
>environment. Every file path is structured just like
>\\wusais\Intranets
>\Intranets\fpdb\pdf\weinig\00505882.pdf. For what I am trying to do,
>I
>have to double up on all of the slashes which is really being a pain.
>At this point, I believe I am going to try and explode the string to
>remove all the slashes and then reassemble it with the correct number
>of slashes.
This doesn't matter where the string comes from. The code I posted
above
$var = strtr($var, array('\\' ='\\\\'));
should work for the strings coming from the database as well.
--
gosha bine
extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok-Hide quoted text -
- Show quoted text -
the code:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>
produces this:
\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\wein ig 05882.pdf
close but the end is still killing me...
That's because your starting string is NOT VALID! See my post above.

Get the string from the database and try parsing it. You'll get a much
different result.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
My problem is that the string coming from the database as variable
with 2 slashes in the front and 1 slash between each directory. Once
the variable comes from the db, I am passing it on to a javascript. If
I pass the variable as is, the script will not work but if I double up
on the slashes everything works fine. So, I have to take the file path
that is coming out of the db and double up on the slashes. Using only
php, everything works fine with the slashes the way they are.


gotcha...it's just hard to express for the purposes of posting here what
jerry would consider a *valid* string (whatever that means), so that we have
something to work with. is that about right?

Steve,

In this case "invalid" would be a backslash NOT followed by a valid
escaped character.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 22 '07 #16

P: n/a
Steve wrote:
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:U6******************************@comcast.com. ..
>dk*******@yahoo.com wrote:
>>On Sep 22, 10:40 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
On Sep 22, 4:28 am, gosha bine <stereof...@gmail.comwrote:
>dkirkd...@yahoo.com wrote:
>>I am having a bit of trouble trying to double up on slashes in a file
>>path. What I am trying to do is very similar to the code below:
>><?
>>$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
>>$new = preg_replace("\\", "\\\", "$var");
>>?>
>>Code above produces the following error:
>>Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
>>\pages\replace.php on line 12
>>In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
>>\pdf\\weinig\\00505882.pdf
>>but it seems to be very difficult replacing slashes.
>>Any help would be greatly appreciated
>$var =
>"\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\w einig\\00505882.pdf";
>echo strtr($var, array('\\' ='\\\\'));
>note that initially $var actually contains only single slashes,
>however
>you must write each slash twice because of php escaping rules.
>--
>gosha bine
>extended php parser ~http://code.google.com/p/pihipi
>blok ~http://www.tagarga.com/blok-Hide quoted text -
>- Show quoted text -
These file paths are coming from a database, they are all windows
paths and they reside on a company intranet so it is a "controlled"
environment. Every file path is structured just like \\wusais\Intranets
\Intranets\fpdb\pdf\weinig\00505882.pdf. For what I am trying to do, I
have to double up on all of the slashes which is really being a pain.
At this point, I believe I am going to try and explode the string to
remove all the slashes and then reassemble it with the correct number
of slashes.
This doesn't matter where the string comes from. The code I posted above

$var = strtr($var, array('\\' ='\\\\'));

should work for the strings coming from the database as well.

--
gosha bine

extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok- Hide quoted text -

- Show quoted text -
the code:

<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>

produces this:

\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weini g05882.pdf

close but the end is still killing me...
That's because your starting string is NOT VALID! See my post above.

NO SUCH THING AS AN INVALID STRING. his problem is understanding the
unexpected results. you already explained that to him, it just seems he's
still lost.
>Get the string from the database and try parsing it. You'll get a much
different result.

php doesn't parse strings whenever it feels like it. the only reason you
have to escape strings *you* create in php is because you have the ability
to put variables in the strings and use octal,hex, and other special
character notation in the string...some of which you cannot use the keyboard
to produce in any other way. but, that's only when YOU are creating them.

if your path is coming from a db, php doesn't care what data type a field
is. if you assign a db field's value to a variable, php just assigns it.
this is quite different than you saying literally that $var = "some
$stringVariable". and that is interpreted differently than $var = 'some
$stringVariable'. one is parsed, the other, literal.

That's true. In the case of data coming from the database, the
equivalent PHP string would be:

"\\\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\wein ig\\00505882.pdf"

When echoes, each double backslash would be printed as a single backslash.

Effectively, when read in from the database, the string would have each
backslash doubled. Then when it is printed the doubled backslashes
would be converted back to single backslashes.

If you echo the above string, you get:

\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505 882.pdf

and my str_replace code would do exactly what he wants.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 22 '07 #17

P: n/a
dk*******@yahoo.com wrote:
On Sep 22, 11:29 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>dkirkd...@yahoo.com wrote:
>>On Sep 22, 10:40 am, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
On Sep 22, 4:28 am, gosha bine <stereof...@gmail.comwrote:
>dkirkd...@yahoo.com wrote:
>>I am having a bit of trouble trying to double up on slashes in a file
>>path. What I am trying to do is very similar to the code below:
>><?
>>$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
>>$new = preg_replace("\\", "\\\", "$var");
>>?>
>>Code above produces the following error:
>>Parse error: parse error, unexpected T_VARIABLE in c:\Inetpub\wwwroot
>>\pages\replace.php on line 12
>>In the end, $new needs to be: \\\\wusais\\Intranets\\Intranets\\fpdb\
>>\pdf\\weinig\\00505882.pdf
>>but it seems to be very difficult replacing slashes.
>>Any help would be greatly appreciated
>$var = "\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig \\00505882.pdf";
>echo strtr($var, array('\\' ='\\\\'));
>note that initially $var actually contains only single slashes, however
>you must write each slash twice because of php escaping rules.
>--
>gosha bine
>extended php parser ~http://code.google.com/p/pihipi
>blok ~http://www.tagarga.com/blok-Hidequoted text -
>- Show quoted text -
These file paths are coming from a database, they are all windows
paths and they reside on a company intranet so it is a "controlled"
environment. Every file path is structured just like \\wusais\Intranets
\Intranets\fpdb\pdf\weinig\00505882.pdf. For what I am trying to do, I
have to double up on all of the slashes which is really being a pain.
At this point, I believe I am going to try and explode the string to
remove all the slashes and then reassemble it with the correct number
of slashes.
This doesn't matter where the string comes from. The code I posted above
$var = strtr($var, array('\\' ='\\\\'));
should work for the strings coming from the database as well.
--
gosha bine
extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok-Hide quoted text -
- Show quoted text -
the code:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>
produces this:
\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weini g 05882.pdf
close but the end is still killing me...
That's because your starting string is NOT VALID! See my post above.

Get the string from the database and try parsing it. You'll get a much
different result.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

My problem is that the string coming from the database as variable
with 2 slashes in the front and 1 slash between each directory. Once
the variable comes from the db, I am passing it on to a javascript. If
I pass the variable as is, the script will not work but if I double up
on the slashes everything works fine. So, I have to take the file path
that is coming out of the db and double up on the slashes. Using only
php, everything works fine with the slashes the way they are.
Your problem is you don't understand that reading a string from the
database is NOT the same as entering the same data as a string in PHP.
Backslashes have a special meaning in PHP.

When read from a database, backslashes are backslashes. But when you
type them into a PHP string, they are escape characters. You have to
double them up to get a backslash in PHP.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 22 '07 #18

P: n/a
dk*******@yahoo.com wrote:
>
the code:

<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>

produces this:

\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf

close but the end is still killing me...
If the string is coming from DB as you have said, you shouldn't be
assigning it to $var, but fetch it from the database instead, like this:

$rc = mysql_query("SELECT .....");
$row = mysql_fetch_array($rc);
$var = $row['fieldname'];

echo strtr($var, array('\\' ='\\\\'));
--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Sep 22 '07 #19

P: n/a
On Sep 22, 3:43 pm, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
the code:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>
produces this:
\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf
close but the end is still killing me...

If the string is coming from DB as you have said, you shouldn't be
assigning it to $var, but fetch it from the database instead, like this:

$rc = mysql_query("SELECT .....");
$row = mysql_fetch_array($rc);
$var = $row['fieldname'];

echo strtr($var, array('\\' ='\\\\'));

--
gosha bine

extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok
Ok, I appreciate all the feed back but maybe I need to post exactly
what I am trying to accomplish.
My variable is coming from a select statement out of a Access db via
an ODBC connection. As it stands right now, I am
using the following code:

<form method="post" action="<?echo $dwg;?>" target="_blank">
<td><p align="center"><button name="open" value="none"
type="submit">open</button></td>
</form>

the variable $dwg is my windows file path that is structured like "\
\wusais\Intranets\Intranets\fpdb\pdf\weinig\005058 82.pdf";
this code works fine, the user clicks the button and a new window
opens displaying the file. I would like to control the window that the
file is opened in so I have to pass the php variable over to
javascript. If I pass it directly to the code below without doubling
the slashes, the file does not open. I have manually doubled the
slashes on a couple of the records in the db and everything works
fine.

javascript code that takes the place of the code posted above:

<form>
<input type="button" onclick="javascript:window.open('<?echo $test;?
>','window','width=800,height=600,resizable=yes,sc rollbars=yes,status=no,toolbar=no')"
value="open">
</td>
</form>

so either I have to change all the records in the db or somewhere
between the db and the javascript the slashes have to be doubled??

Sep 22 '07 #20

P: n/a
dk*******@yahoo.com wrote:
On Sep 22, 3:43 pm, gosha bine <stereof...@gmail.comwrote:
>dkirkd...@yahoo.com wrote:
>>the code:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>
produces this:
\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weini g 05882.pdf
close but the end is still killing me...
If the string is coming from DB as you have said, you shouldn't be
assigning it to $var, but fetch it from the database instead, like this:

$rc = mysql_query("SELECT .....");
$row = mysql_fetch_array($rc);
$var = $row['fieldname'];

echo strtr($var, array('\\' ='\\\\'));

--
gosha bine

extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok

Ok, I appreciate all the feed back but maybe I need to post exactly
what I am trying to accomplish.
My variable is coming from a select statement out of a Access db via
an ODBC connection. As it stands right now, I am
using the following code:

<form method="post" action="<?echo $dwg;?>" target="_blank">
<td><p align="center"><button name="open" value="none"
type="submit">open</button></td>
</form>

the variable $dwg is my windows file path that is structured like "\
\wusais\Intranets\Intranets\fpdb\pdf\weinig\005058 82.pdf";
this code works fine, the user clicks the button and a new window
opens displaying the file. I would like to control the window that the
file is opened in so I have to pass the php variable over to
javascript. If I pass it directly to the code below without doubling
the slashes, the file does not open. I have manually doubled the
slashes on a couple of the records in the db and everything works
fine.

javascript code that takes the place of the code posted above:

<form>
<input type="button" onclick="javascript:window.open('<?echo $test;?
>','window','width=800,height=600,resizable=yes,sc rollbars=yes,status=no,toolbar=no')"
value="open">
</td>
</form>

so either I have to change all the records in the db or somewhere
between the db and the javascript the slashes have to be doubled??
As we've been trying to tell you. Use the techniques posted to modify
the string after you get it from the database but before you echo it to
the screen for your javascript.

You don't have to double the backslashes in the database - in fact, you
shouldn't. Just try it - and if it doesn't work, post the exact PHP
code you're using with one of the suggestions installed.

Personally I like the str_replace version. It only works with one
string at a time while gosha's can replace multiple string. But mine
is faster when dealing with a single string.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 22 '07 #21

P: n/a
dk*******@yahoo.com wrote:
[snip]

so either I have to change all the records in the db or somewhere
between the db and the javascript the slashes have to be doubled??
Use the code I gave you above.
--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Sep 23 '07 #22

P: n/a

<dk*******@yahoo.comwrote in message
news:11**********************@50g2000hsm.googlegro ups.com...
On Sep 22, 3:43 pm, gosha bine <stereof...@gmail.comwrote:
>dkirkd...@yahoo.com wrote:
the code:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>
produces this:
\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf
close but the end is still killing me...

If the string is coming from DB as you have said, you shouldn't be
assigning it to $var, but fetch it from the database instead, like this:

$rc = mysql_query("SELECT .....");
$row = mysql_fetch_array($rc);
$var = $row['fieldname'];

echo strtr($var, array('\\' ='\\\\'));

--
gosha bine

extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok

Ok, I appreciate all the feed back but maybe I need to post exactly
what I am trying to accomplish.
My variable is coming from a select statement out of a Access db via
an ODBC connection. As it stands right now, I am
using the following code:

<form method="post" action="<?echo $dwg;?>" target="_blank">
<td><p align="center"><button name="open" value="none"
type="submit">open</button></td>
</form>

the variable $dwg is my windows file path that is structured like "\
\wusais\Intranets\Intranets\fpdb\pdf\weinig\005058 82.pdf";
this code works fine, the user clicks the button and a new window
opens displaying the file. I would like to control the window that the
file is opened in so I have to pass the php variable over to
javascript. If I pass it directly to the code below without doubling
the slashes, the file does not open. I have manually doubled the
slashes on a couple of the records in the db and everything works
fine.

javascript code that takes the place of the code posted above:

<form>
<input type="button" onclick="javascript:window.open('<?echo $test;?
>>','window','width=800,height=600,resizable=yes,s crollbars=yes,status=no,toolbar=no')"
value="open">
</td>
</form>

so either I have to change all the records in the db or somewhere
between the db and the javascript the slashes have to be doubled??
Here is a suggesion.

Since you know that the ONLY place you need quadruple quotes is at the very
beginning to indicate the machine, why not do something like:

$original = '\\wusais\Intranets\Intranets\fpdb\pdf\new\0050588 2.pdf';
$nextone = "\\\\" . str_replace("\\", "\\\\", $original);
echo $original . "<br>";
echo $nextone . "<br>";

The output of this is:
\wusais\Intranets\Intranets\fpdb\pdf\new\00505882. pdf
\\\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\new\\ 00505882.pdf

Shelly

Not that I changed you quotes to tics in $original. This is so that there
would not be a problem with \new or with \005.
Sep 23 '07 #23

P: n/a
On Sep 23, 7:52 am, "Shelly" <sheldonlg.n...@asap-consult.comwrote:
<dkirkd...@yahoo.comwrote in message

news:11**********************@50g2000hsm.googlegro ups.com...


On Sep 22, 3:43 pm, gosha bine <stereof...@gmail.comwrote:
dkirkd...@yahoo.com wrote:
the code:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\0050 5882.pdf";
echo strtr($var, array('\\' ='\\\\'));
?>
produces this:
\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig 05882.pdf
close but the end is still killing me...
If the string is coming from DB as you have said, you shouldn't be
assigning it to $var, but fetch it from the database instead, like this:
$rc = mysql_query("SELECT .....");
$row = mysql_fetch_array($rc);
$var = $row['fieldname'];
echo strtr($var, array('\\' ='\\\\'));
--
gosha bine
extended php parser ~http://code.google.com/p/pihipi
blok ~http://www.tagarga.com/blok
Ok, I appreciate all the feed back but maybe I need to post exactly
what I am trying to accomplish.
My variable is coming from a select statement out of a Access db via
an ODBC connection. As it stands right now, I am
using the following code:
<form method="post" action="<?echo $dwg;?>" target="_blank">
<td><p align="center"><button name="open" value="none"
type="submit">open</button></td>
</form>
the variable $dwg is my windows file path that is structured like "\
\wusais\Intranets\Intranets\fpdb\pdf\weinig\005058 82.pdf";
this code works fine, the user clicks the button and a new window
opens displaying the file. I would like to control the window that the
file is opened in so I have to pass the php variable over to
javascript. If I pass it directly to the code below without doubling
the slashes, the file does not open. I have manually doubled the
slashes on a couple of the records in the db and everything works
fine.
javascript code that takes the place of the code posted above:
<form>
<input type="button" onclick="javascript:window.open('<?echo $test;?
>','window','width=800,height=600,resizable=yes,sc rollbars=yes,status=no,t*oolbar=no')"
value="open">
</td>
</form>
so either I have to change all the records in the db or somewhere
between the db and the javascript the slashes have to be doubled??

Here is a suggesion.

Since you know that the ONLY place you need quadruple quotes is at the very
beginning to indicate the machine, why not do something like:

$original = '\\wusais\Intranets\Intranets\fpdb\pdf\new\0050588 2.pdf';
$nextone = "\\\\" . str_replace("\\", "\\\\", $original);
echo $original . "<br>";
echo $nextone . "<br>";

The output of this is:
\wusais\Intranets\Intranets\fpdb\pdf\new\00505882. pdf
\\\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\new\\ 00505882.pdf

Shelly

Not that I changed you quotes to tics in $original. This is so that there
would not be a problem with \new or with \005.- Hide quoted text -

- Show quoted text -
Thanks for all the feed back, I have to wait until tomorrow until I am
able to try it with the db. I was trying to come up with a way to
solve my slash issues without the db and figured if I could echo out
the variable with the correct number of slashes, all would be ok.
Again thanks for all the help and I will post my findings tomorrow.

Sep 23 '07 #24

This discussion thread is closed

Replies have been disabled for this discussion.