Php strpos()未找到//&引用;?
这是页面:[我删除了URL,它不再存在] 我的问题是data.bdf中的注释除了第一个之外没有格式化 这是php:Php strpos()未找到//&引用;?,php,strpos,Php,Strpos,这是页面:[我删除了URL,它不再存在] 我的问题是data.bdf中的注释除了第一个之外没有格式化 这是php: <html> <head> <title>Text Database Editor</title> <style type="text/css"> span.comment { color:green; } </style> <script type="text/javascript"> f
<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);?>
文本数据库编辑器
评论{
颜色:绿色;
}
函数setURLValue(){
document.getElementById(“url”).value=window.location;
}
写入文件:
您应该使用!==错误
,即
if (strpos($fileline[$count], "//" ) !== false) {
您应该使用!==错误
,即
if (strpos($fileline[$count], "//" ) !== false) {
explorate()
中的return
语句位于错误的位置。它应该在循环之外:
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;
}
函数解释($fileline){
对于($count=1;!empty($fileline[$count]);$count++){
if(strpos($fileline[$count],“/”)==0){
$fileline[$count]=substr($fileline[$count],2);
$fileline[$count]=“”.$fileline[$count]。“”;
}
}
返回$fileline;
}
在explorate()
中的return
语句位于错误的位置。它应该在循环之外:
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;
}
函数解释($fileline){
对于($count=1;!empty($fileline[$count]);$count++){
if(strpos($fileline[$count],“/”)==0){
$fileline[$count]=substr($fileline[$count],2);
$fileline[$count]=“”.$fileline[$count]。“”;
}
}
返回$fileline;
}
我不明白这是一个修复吗?strpos
返回一个整数或false
,因此您需要将其与false
进行比较,nottrue
。这与floernsis一起修复了它。我不明白这是修复吗?strpos
返回一个整数或false
,因此您需要将其与false
进行比较,而不是true
。这与PHP中的floernsarray一起修复了它,它从位置0开始,而不是1。检查$count
。这不是问题所在,因为PHP中的0元素是“”数组从位置0开始,而不是1。检查您的$count
。这不是问题所在,因为0元素是“我用strpos
解决了问题,我想您只想在字符串开头匹配/
,因此您必须与==0
进行比较。我用strpos
解决了问题,我猜您只想在字符串开头匹配/
,因此必须与==0