首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >strpos()找不到"//"?

strpos()找不到"//"?
EN

Stack Overflow用户
提问于 2011-06-17 06:08:35
回答 2查看 281关注 0票数 0

这是页面:我删除了URL,它已经不存在了

我的问题是,除了第一个之外,data.bdf中的注释没有格式化。

这是php:

代码语言:javascript
复制
<html>
<head>
<title>Text Database Editor</title>
<style type="text/css">
span.comment {
    color:green;
}
</style>
<script type="text/javascript">
function setURLValue() {
    document.getElementById("url").value=window.location;
}
</script>
</head>
<body onLoad="setURLValue();">
<?php
function interpret($fileline) {
    for ($count=1;!empty($fileline[$count]);$count++) {
        if (strpos($fileline[$count],"//")==0) {
            $fileline[$count]=substr($fileline[$count],2);
            $fileline[$count]="<span class=\"comment\">".$fileline[$count]."</span>";
        }
        return $fileline;
    }
}
$filepath = "data.bdf";
$filesize = @filesize($filepath);
if (!empty($filesize)) {
    echo "File being opened contains ".$filesize." bytes of data. Opening file...<br />";
}
else {
    echo "Error in determining file size. ";
}
$handle = @fopen($filepath, "r") or die("File could not be opened");
echo "File Opened!<br />";
$filedata = fread($handle, $filesize+1) or die("File could not be read");
echo "File Read!<br /><br />Data in file:<br /><br />";
$fileline = explode("`",$filedata);
$fileline = interpret($fileline);
for ($count=1;!empty($fileline[$count]);$count++) {
    echo $count.": ".$fileline[$count]."<br />";
}
?>
<br />Write to file:
<form name="writeto" action="write_to_file.php" method="post">
<input type="hidden" name="formurl" id="url" />
<input type="hidden" name="file" value="<?php echo $filepath;?>" />
<input type="radio" name="iscomment" value="Yes" />Comment
<input type="radio" name="iscomment" value="No" />Data<br />
Text: <input type="text" name="text" />
<input type="submit" />
</form>
</body>
</html>
<?php fclose($handle);?>

谢谢你的帮助..。

顺便说一下,我不再有写两次的bug了。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-06-17 06:12:53

interpret()中的return语句位于错误的位置。它应该在循环之外:

代码语言:javascript
复制
function interpret($fileline) {
    for ($count=1;!empty($fileline[$count]);$count++) {
        if (strpos($fileline[$count],"//")===0) {
            $fileline[$count]=substr($fileline[$count],2);
            $fileline[$count]="<span class=\"comment\">".$fileline[$count]."</span>";
        }
    }
    return $fileline;
}
票数 3
EN

Stack Overflow用户

发布于 2011-06-17 06:10:41

您应该使用!== false,即

代码语言:javascript
复制
if (strpos($fileline[$count], "//" ) !== false) {
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6379217

复制
相关文章

相似问题

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