首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于从.php文件中抓取字符集的php代码,给出错误消息

用于从.php文件中抓取字符集的php代码,给出错误消息
EN

Stack Overflow用户
提问于 2012-01-13 07:04:36
回答 1查看 65关注 0票数 1

提前谢谢。

使用以下代码时出现此警告:

警告: file_get_contents(test.php)函数.file-get-contents:无法打开流:在so-n-so行的/path/index.php中没有这样的文件或目录。

这是我使用的代码,

代码语言:javascript
复制
<?php

// Scan directory for files
$dir = "path/";
$files = scandir($dir);

// Iterate through the list of files 
foreach($files as $file)
{
// Determine info about the file
$parts = pathinfo($file);

// If the file extension == php
if ( $parts['extension'] === "php" )
{
// Read the contents of the file
$contents = file_get_contents($file);

// Find first occurrence of opening template tag
$from = strpos($contents, "{{{{{");

// Find first occurrence of ending template tag
$to = strpos($contents,"}}}}}");

// Pull out the unique name from between the template tags
$uniqueName = substr($contents, $from+5, $to);

// Print out the unique name
echo $uniqueName ."<br/>";
}
}
?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-13 07:07:29

错误消息指出找不到该文件。

这是因为scandir()只返回目录中文件的基本名称。它不包括目录名。您可以改用glob()

代码语言:javascript
复制
$files = glob("$dir/*.php");

这将返回结果列表中的路径,还会使您的扩展检查变得多余。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8843649

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档