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.

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

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line