Thank you Stian!

In Swedish they say "Sometimes you can't see the forest by all the trees."

/frank

2005-02-24 kl. 09.45 skrev Stian Berger:

On Thu, 24 Feb 2005 09:14:32 +0100, Frank Arensmeier <[EMAIL PROTECTED]> 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 = "..\1 PDF Filer\65051.PDF";
$things_to_look_for = array("..", "\");
$things_to_replace_with = array("file://server/folder", "/");
$link = 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 error 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 = addslashes("..\1 PDF Filer\65051.PDF");
$things_to_look_for = 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 line character, while \\n on the other hand means \ followed by n.

Manual: http://www.php.net/types.string

--
Stian

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php




Reply via email to