开发者

PHP Parsing error results from string variable containing a drive path

I'm getting an error

Parse error: syntax error, unexpected T_STRING

On the line with $szSearchDBPath below. It seems like PHP doesn't like something about the drive path.

I've spent hours Googling to try and find the problem, but with no success.

From my understanding, a single quoted string is not parsed and should be interpreted literally.

Does anyone know what could be the problem?

<?php
$szHost = getcwd()开发者_运维百科;
$szAddDir = "";
$g_bSaveSearch = 'True';
$szContentRoot = 'd:\websites\lycos\Alpha_Pourri\';
$szSearchDBPath = 'd:\websites\lycos\Alpha_Pourri\searches\';
$bPRODSite = 'False';
$i = 0;
...


Since backslashes are used for escape characters, you're accidentally escaping the ending single quote by putting a backslash before it. Try turning all your backslashes into double backslashes, eg

$szContentRoot = 'd:\\websites\\lycos\\Alpha_Pourri\\';


Backslashes are technically escape characters in PHP, so you must double escape them:

<?php
$szHost = getcwd();
$szAddDir = "";
$g_bSaveSearch = 'True';
$szContentRoot = 'd:\\websites\\lycos\\Alpha_Pourri\\';
$szSearchDBPath = 'd:\\websites\\lycos\\Alpha_Pourri\\searches\\';
$bPRODSite = 'False';
$i = 0;

For more information about this you can refer to the manual entry about strings:

To specify a literal single quote, escape it with a backslash (). To specify a literal backslash, double it (\). ...


$szContentRoot = 'd:\websites\lycos\Alpha_Pourri\';

The \ escapes the single quote ', thus the string doesn't end there. Escape the backslash

$szContentRoot = 'd:\websites\lycos\Alpha_Pourri\\';

It should be sufficient to escape the last one (because its in single quotes). However, you may replace every \ with \\. Or you just use the common forward slash /, because windows accept both as directory separator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜