duanchuli5647 2016-09-22 05:16
浏览 98
已采纳

为什么include_path中的反斜杠会被破坏?

I'm using the following code to be able to easily test my page on my dev machine and the shared host:

$include_path_afrihost = "../php/Services/facebook/php-graph-sdk-5.0.0/src/Facebook";
$include_path_dev = __DIR__."\sdk\facebook\php-graph-sdk-5.0.0\src\Facebook";
ini_set("include_path", $include_path_afrihost . PATH_SEPARATOR . $include_path_dev);
require_once "Facebook.php";

When I try and run the code, I get the following exception:

require_once(): Failed opening required 'Facebook.php' (include_path='../php/Services/facebook/php-graph-sdk-5.0.0/src/Facebook;C:\Dev\PHP\Projects\Messenger\Code\FacebookClient\sdkacebook\php-graph-sdk-5.0.0\src\Facebook')

Please note the mess in the dev include path with "\FacebookClient\sdkacebook\", where a backslash and the 'f' for 'facebook' are missing. I copied the path directly from the address bar in Windows File Explorer, and all the other backslashes are fine.

If I change the one line and make the funny backslash double, e.g:

$include_path_dev = __DIR__."\sdk\\facebook\php-graph-sdk-5.0.0\src\Facebook";

then the code works fine.

  • 写回答

1条回答 默认 最新

  • douping4436 2016-09-22 05:20
    关注

    \f is being read as an escape character, similar to how is newline.

    Using a second backslash escapes the backslash: \\f becomes \f. In general, you should always escape backslashes to avoid this problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?