replace single slash with double slash

replace single slash with double slash

am 22.09.2007 02:31:50 von dkirkdrei

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\00505882.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

Re: replace single slash with double slash

am 22.09.2007 03:32:18 von Jerry Stuckle

dkirkdrei@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\00505882.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.
jstucklex@attglobal.net
==================

Re: replace single slash with double slash

am 22.09.2007 03:39:46 von dkirkdrei

On Sep 21, 9:32 pm, Jerry Stuckle wrote:
> 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 =3D "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.pdf";
> > $new =3D 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 =3D "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.pdf";
$new =3D str_replace("\\", "\\\\", "$var");
?>

and received:

\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig05882.pdf

Re: replace single slash with double slash

am 22.09.2007 04:46:13 von Jerry Stuckle

dkirkdrei@yahoo.com wrote:
> On Sep 21, 9:32 pm, Jerry Stuckle wrote:
>> 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\00505882.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\00505882.pdf";
> $new = str_replace("\\", "\\\\", "$var");
> ?>
>
> and received:
>
> \\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig05882.pdf
>

First of all,

$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.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.
jstucklex@attglobal.net
==================

Re: replace single slash with double slash

am 22.09.2007 06:09:46 von Steve

"Jerry Stuckle" wrote in message
news:qfydnT5dxKbCH2nbnZ2dnUVZ_v6rnZ2d@comcast.com...
> dkirkdrei@yahoo.com wrote:
>> On Sep 21, 9:32 pm, Jerry Stuckle wrote:
>>> 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\00505882.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\00505882.pdf";
>> $new = str_replace("\\", "\\\\", "$var");
>> ?>
>>
>> and received:
>>
>> \\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig05882.pdf
>>
>
> First of all,
>
> $var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.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.

Re: replace single slash with double slash

am 22.09.2007 10:28:37 von gosha bine

dkirkdrei@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\00505882.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

Re: replace single slash with double slash

am 22.09.2007 14:33:32 von dkirkdrei

On Sep 22, 4:28 am, gosha bine wrote:
> 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\00505882.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.

Re: replace single slash with double slash

am 22.09.2007 16:09:41 von Jerry Stuckle

dkirkdrei@yahoo.com wrote:
> On Sep 22, 4:28 am, gosha bine wrote:
>> 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\00505882.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\00505882.pdf";

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

$var = "\\\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig\\005058 82.pdf";
echo $var , "\n";
$new = str_replace('\\', '\\\\', $var);
echo $new;
?>

Output:

\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.pdf
\\\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig\\0050588 2.pdf


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

Re: replace single slash with double slash

am 22.09.2007 16:40:47 von gosha bine

dkirkdrei@yahoo.com wrote:
> On Sep 22, 4:28 am, gosha bine wrote:
>> 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\00505882.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

Re: replace single slash with double slash

am 22.09.2007 17:26:10 von dkirkdrei

On Sep 22, 10:40 am, gosha bine wrote:
> dkirkd...@yahoo.com wrote:
> > On Sep 22, 4:28 am, gosha bine wrote:
> >> 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 =3D "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.pdf";
> >>> $new =3D 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 =3D "\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig\\00505882 .=
pdf";
>
> >> echo strtr($var, array('\\' =3D> '\\\\'));
>
> >> 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 =3D strtr($var, array('\\' =3D> '\\\\'));
>
> 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 =3D "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.pdf";
echo strtr($var, array('\\' =3D> '\\\\'));
?>

produces this:

\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig05882.pdf

close but the end is still killing me...

Re: replace single slash with double slash

am 22.09.2007 17:29:34 von Jerry Stuckle

dkirkdrei@yahoo.com wrote:
> On Sep 22, 10:40 am, gosha bine wrote:
>> dkirkd...@yahoo.com wrote:
>>> On Sep 22, 4:28 am, gosha bine wrote:
>>>> 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\00505882.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\00505882.pdf";
> echo strtr($var, array('\\' => '\\\\'));
> ?>
>
> produces this:
>
> \\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig05882.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.
jstucklex@attglobal.net
==================

Re: replace single slash with double slash

am 22.09.2007 17:39:49 von dkirkdrei

On Sep 22, 11:29 am, Jerry Stuckle wrote:
> dkirkd...@yahoo.com wrote:
> > On Sep 22, 10:40 am, gosha bine wrote:
> >> dkirkd...@yahoo.com wrote:
> >>> On Sep 22, 4:28 am, gosha bine wrote:
> >>>> 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\00505882.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\00505882.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.

Re: replace single slash with double slash

am 22.09.2007 20:41:03 von Steve

"Jerry Stuckle" wrote in message
news:U6KdnUWe_eTaqGjbnZ2dnUVZ_ofinZ2d@comcast.com...
> dkirkdrei@yahoo.com wrote:
>> On Sep 22, 10:40 am, gosha bine wrote:
>>> dkirkd...@yahoo.com wrote:
>>>> On Sep 22, 4:28 am, gosha bine wrote:
>>>>> 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\00505882.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\00505882.pdf";
>> echo strtr($var, array('\\' => '\\\\'));
>> ?>
>>
>> produces this:
>>
>> \\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig05882.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.

Re: replace single slash with double slash

am 22.09.2007 20:43:08 von Steve

wrote in message
news:1190475589.522207.39050@o80g2000hse.googlegroups.com...
> On Sep 22, 11:29 am, Jerry Stuckle wrote:
>> dkirkd...@yahoo.com wrote:
>> > On Sep 22, 10:40 am, gosha bine wrote:
>> >> dkirkd...@yahoo.com wrote:
>> >>> On Sep 22, 4:28 am, gosha bine wrote:
>> >>>> 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\00505882.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\00505882.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?

Re: replace single slash with double slash

am 22.09.2007 21:04:19 von dkirkdrei

On Sep 22, 2:43 pm, "Steve" wrote:
> wrote in message
>
> news:1190475589.522207.39050@o80g2000hse.googlegroups.com...
>
>
>
>
>
> > On Sep 22, 11:29 am, Jerry Stuckle wrote:
> >> dkirkd...@yahoo.com wrote:
> >> > On Sep 22, 10:40 am, gosha bine wrote:
> >> >> dkirkd...@yahoo.com wrote:
> >> >>> On Sep 22, 4:28 am, gosha bine wrote:
> >> >>>> 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\00505882.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-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\00505882.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\00505882.pdf";

into this using php:

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

Re: replace single slash with double slash

am 22.09.2007 21:11:52 von Jerry Stuckle

Steve wrote:
> wrote in message
> news:1190475589.522207.39050@o80g2000hse.googlegroups.com...
>> On Sep 22, 11:29 am, Jerry Stuckle wrote:
>>> dkirkd...@yahoo.com wrote:
>>>> On Sep 22, 10:40 am, gosha bine wrote:
>>>>> dkirkd...@yahoo.com wrote:
>>>>>> On Sep 22, 4:28 am, gosha bine wrote:
>>>>>>> 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\00505882.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\00505882.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?
>
>

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.
jstucklex@attglobal.net
==================

Re: replace single slash with double slash

am 22.09.2007 21:16:42 von Jerry Stuckle

Steve wrote:
> "Jerry Stuckle" wrote in message
> news:U6KdnUWe_eTaqGjbnZ2dnUVZ_ofinZ2d@comcast.com...
>> dkirkdrei@yahoo.com wrote:
>>> On Sep 22, 10:40 am, gosha bine wrote:
>>>> dkirkd...@yahoo.com wrote:
>>>>> On Sep 22, 4:28 am, gosha bine wrote:
>>>>>> 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\00505882.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\00505882.pdf";
>>> echo strtr($var, array('\\' => '\\\\'));
>>> ?>
>>>
>>> produces this:
>>>
>>> \\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig05882.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\\weinig\\005058 82.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\00505882.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.
jstucklex@attglobal.net
==================

Re: replace single slash with double slash

am 22.09.2007 21:20:18 von Jerry Stuckle

dkirkdrei@yahoo.com wrote:
> On Sep 22, 11:29 am, Jerry Stuckle wrote:
>> dkirkd...@yahoo.com wrote:
>>> On Sep 22, 10:40 am, gosha bine wrote:
>>>> dkirkd...@yahoo.com wrote:
>>>>> On Sep 22, 4:28 am, gosha bine wrote:
>>>>>> 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\00505882.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\00505882.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.
>

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.
jstucklex@attglobal.net
==================

Re: replace single slash with double slash

am 22.09.2007 21:43:47 von gosha bine

dkirkdrei@yahoo.com wrote:
>
> the code:
>
> > $var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.pdf";
> echo strtr($var, array('\\' => '\\\\'));
> ?>
>
> produces this:
>
> \\wusais\\Intranets\\Intranets\\fpdb\\pdf\\weinig05882.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

Re: replace single slash with double slash

am 23.09.2007 00:01:43 von dkirkdrei

On Sep 22, 3:43 pm, gosha bine wrote:
> dkirkd...@yahoo.com wrote:
>
> > the code:
>
> > > > $var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.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:





the variable $dwg is my windows file path that is structured like "\
\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.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:


value="open">



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

Re: replace single slash with double slash

am 23.09.2007 00:35:43 von Jerry Stuckle

dkirkdrei@yahoo.com wrote:
> On Sep 22, 3:43 pm, gosha bine wrote:
>> dkirkd...@yahoo.com wrote:
>>
>>> the code:
>>> >>> $var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.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:
>
>


>


>


>
> the variable $dwg is my windows file path that is structured like "\
> \wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.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:
>
>

> > value="open">
>
>

>
> 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.
jstucklex@attglobal.net
==================

Re: replace single slash with double slash

am 23.09.2007 01:22:57 von Steve

wrote in message
news:1190498503.311214.302020@50g2000hsm.googlegroups.com...
> On Sep 22, 3:43 pm, gosha bine wrote:
>> dkirkd...@yahoo.com wrote:
>>
>> > the code:
>>
>> > >> > $var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.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:
>
>


>


>


>
> the variable $dwg is my windows file path that is structured like "\
> \wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.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:

if ever i wanted a chance to hack a web application, i'd start by looking at
the js. you need to keep your file system information to yourself! if you
need to give a file to a web user or to use other systems resources, YOU
need to get them and then give the RESULT back to the user. if i know where
your network shares are (since they're happily in the js), i don't need your
front-end at all in order to puruse your system. i also know to apply
windows-based hacks to do even more damage since the unc is unique to that
os.

i love websites that also put their sql statements in js so they can use
them in conjunction with ajax. hell, tell me more about your
system...please!

Re: replace single slash with double slash

am 23.09.2007 11:33:07 von gosha bine

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

Re: replace single slash with double slash

am 23.09.2007 13:52:26 von Shelly

wrote in message
news:1190498503.311214.302020@50g2000hsm.googlegroups.com...
> On Sep 22, 3:43 pm, gosha bine wrote:
>> dkirkd...@yahoo.com wrote:
>>
>> > the code:
>>
>> > >> > $var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.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:
>
>


>


>


>
> the variable $dwg is my windows file path that is structured like "\
> \wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.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:
>
>

> > value="open">
>
>

>
> 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\00505882.pdf';
$nextone = "\\\\" . str_replace("\\", "\\\\", $original);
echo $original . "
";
echo $nextone . "
";

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

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.

Re: replace single slash with double slash

am 23.09.2007 16:48:55 von dkirkdrei

On Sep 23, 7:52 am, "Shelly" wrote:
> wrote in message
>
> news:1190498503.311214.302020@50g2000hsm.googlegroups.com...
>
>
>
>
>
> > On Sep 22, 3:43 pm, gosha bine wrote:
> >> dkirkd...@yahoo.com wrote:
>
> >> > the code:
>
> >> > > >> > $var =3D "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.pdf";
> >> > echo strtr($var, array('\\' =3D> '\\\\'));
> >> > ?>
>
> >> > 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 thi=
s:
>
> >> $rc =3D mysql_query("SELECT .....");
> >> $row =3D mysql_fetch_array($rc);
> >> $var =3D $row['fieldname'];
>
> >> echo strtr($var, array('\\' =3D> '\\\\'));
>
> >> --
> >> 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:
>
> >

" target=3D"_blank">
> >


> >


>
> > the variable $dwg is my windows file path that is structured like "\
> > \wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.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:
>
> >

> > > >>','window','width=3D800,height=3D600,resizable=3Dyes,scrol lbars=3Dyes,s=
tatus=3Dno,t=ADoolbar=3Dno')"
> > value=3D"open">
> >
> >

>
> > 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 ve=
ry
> beginning to indicate the machine, why not do something like:
>
> $original =3D '\\wusais\Intranets\Intranets\fpdb\pdf\new\00505882.pdf';
> $nextone =3D "\\\\" . str_replace("\\", "\\\\", $original);
> echo $original . "
";
> echo $nextone . "
";
>
> The output of this is:
> \wusais\Intranets\Intranets\fpdb\pdf\new\00505882.pdf
> \\\\wusais\\Intranets\\Intranets\\fpdb\\pdf\\new\\00505882.p df
>
> 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.