here is the page: [I removed the URL, it doesn't exist anymore]
my problem is that comments in the data.bdf are not formatted except for the first one.
this is the php:
开发者_运维知识库<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);?>
Thanks for helping...
by the way i no longer have the bug with writing twice
The return
statement in interpret()
is at the wrong place. It should be outside the loop:
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;
}
You should use !== false
, i.e.
if (strpos($fileline[$count], "//" ) !== false) {
精彩评论