You are here: Re: replace single slash with double slash « PHP Programming Language « IT news, forums, messages
Re: replace single slash with double slash

Posted by Shelly on 09/23/07 11:52

<dkirkdrei@yahoo.com> wrote in message
news:1190498503.311214.302020@50g2000hsm.googlegroups.com...
> On Sep 22, 3:43 pm, gosha bine <stereof...@gmail.com> 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:
>
> <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\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:
>
> <form>
> <input type="button" onclick="javascript:window.open('<?echo $test;?
>>','window','width=800,height=600,resizable=yes,scrollbars=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\00505882.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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация