|
Posted by Stian Berger on 02/24/05 10:45
On Thu, 24 Feb 2005 09:14:32 +0100, Frank Arensmeier =
<frank.arensmeier@nikehydraulics.se> wrote:
> Hello everybody!
>
> I was wondering if you could help me with a little problem I ran into =
=
> some days ago.
>
> In my database I have some information about file paths. Originally, =
> those paths come from a Windows Excel spreadsheet and look like "..\1 =
=
> PDF Filer\65051.PDF". In my PHP code I try to do two things:
>
> 1) replace ".." with a string like "file://server/folder"
> 2) replace all "\" characters with "/".
>
> The PHP code looks something like:
>
> $path_to_file =3D "..\1 PDF Filer\65051.PDF";
> $things_to_look_for =3D array("..", "\");
> $things_to_replace_with =3D array("file://server/folder", "/");
> $link =3D str_replace($things_to_look_for, $things_to_replace_with, =
> $path_to_file);
>
> The big problem is the character "\" which, if I got it right, in =
> UNICODE is used for things like expressing line breaks ('\n' or =
> something like this). The code above is resulting in the following err=
or =
> massage: "Parse error: parse error, expecting `')'' in =
> /xxx/xxx/xxx/TMPz06yoces6o.php on line 2."
>
> Is there a simple solution for this problem?
>
> Regards,
>
> Frank
You are escaping the last quote, meaning that the rest of your code is =
"quoted". What you need to do is to escape the escape character.
$path_to_file =3D addslashes("..\1 PDF Filer\65051.PDF");
$things_to_look_for =3D array("..", "\\");
You should use addslashes() or similar on you're path name, as some =
escaped characters have certain meanings. \n for example means a new lin=
e =
character, while \\n on the other hand means \ followed by n.
Manual: http://www.php.net/types.string
-- =
Stian
[Back to original message]
|