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 Jerry Stuckle on 09/22/07 14:09

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


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

 

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

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