473,394 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

replace single slash with double slash

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
23 13382
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
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
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

"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
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
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
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
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
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
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
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

"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

<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
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
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
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
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
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
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
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
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

<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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to...
12
by: Joshua Beall | last post by:
Hi All, I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted strings (e.g., 'Hello, World'). This seems backwards...
2
by: Diarmaid McGleenan | last post by:
Hi all. This isn't quite the same single/double-quote problem we see posted a multitude of times in this ng. Read on... I have a js function called ShowActiveLink which accepts a string...
1
by: davegraham_1998 | last post by:
Hi All- I'm pretty sure this have been discussed earlier, but couldn't find a solution to my problem. <input type="submit" value="Delete Parts" onclick="return handleDeleteParts('ABC', 'MY...
9
by: Tim Anderson | last post by:
Does anyone else think VB should support the // prefix for comments? I keep using it by accident, because so many other languages use it (unlike the single quote, which is I believe unique to VB)....
6
by: Sakharam Phapale | last post by:
Hi All, How to capture Mouse Single click and mouse double click event on Commnad Button. I am doing as follows. Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As...
7
by: Tor Aadnevik | last post by:
Hi, I have a problem converting values from Single to double. eg. When the Single value 12.19 is converted to double, the result is 12.1899995803833. Anyone know how to avoid this? Regards...
6
by: R.Biloti | last post by:
Hi folks I wrote the naive program to show up the unit roundoff (machine precision) for single and double precision: #include <stdio.h> int main (void) { double x;
1
by: eaocomp | last post by:
How do I trigger a single or double-click events when a user clicks a column within the gridview. I want the event to trigger and open a pop-up page related to the selected column. There are no...
6
by: Nathan Sokalski | last post by:
I know that Single and Double can only store values that can be stored as x/2^y, such as 0.5 and 0.125. But when they attempt to store values such as 0.1 or 0.2 whose exact value cannot be stored,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...

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.