【问题标题】:PHP returning part of the code documentPHP 返回部分代码文档
【发布时间】:2011-01-30 04:29:00
【问题描述】:

我有一个 PHP 页面,根据在 GET 数据中设置的 action 执行几项不同的操作。视情况而定,它应该返回一些 JSON,但它不做任何应该做的事情,而是返回代码文档本身的下半部分,从行的中间开始。这是它开始的片段:

...
} elseif ($_GET['action'] == 'addtop') {
    if (!isset($_GET['pname']) || !isset($_GET['url']) || !isset($_GET['artist']) || !isset($_GET['album']) || !isset($_GET['file'])) {
        die('Error: Incomplete data!');
    }
    if (!file_exists($_GET['pname'].".txt")) {
        die('Error: No such playlist!');
    }
    $plist = json_decode(file_get_contents($_GET['pname'].".txt"), true);
    $fh = fopen($_GET['pname'].".txt", 'w') or die('Could not open playlist!');
    array_push($plist, array("artist" => $_GET['artist'], "album" => $_GET['album'], "file" => $_GET['file'], "url" => $_GET['url']));
    fwrite($fh,json_encode($plist));
} elseif ($_GET['action'] == 'delfromp') {
...

当我转到该页面时,这是我得到的:

$_GET['艺术家'], "专辑" => $_GET['专辑'], "文件" => $_GET['file'], "url" => $_GET['url'])); fwrite($fh,json_encode($plist)); } elseif ($_GET['action'] == 'delfromp') { if (!isset($_GET['pname']) || !isset($_GET['id'])) { die('错误: 数据不完整!'); } 如果 (!file_exists($_GET['pname'].".txt")) { die('错误:没有这样的播放列表!'); } $plist = json_decode(file_get_contents($_GET['pname'].".txt"), 真的); $fh = fopen($_GET['pname'].".txt", 'w') 或 die('无法打开播放列表!'); 未设置($plist[$_GET['id']]); $plist = 数组值($plist); fwrite($fh,json_encode($plist)); } elseif ($_GET['action'] == 'readp') { 如果 (!file_exists($_GET['pname'].".txt")) { die('错误:没有这样的播放列表!'); } $plist = json_decode(file_get_contents($_GET['pname'].".txt"), 真的); $arr = 数组(“条目” => $plist); $json = json_encode($arr); 回声 $json; } elseif ($_GET['action'] == 'getps') { $plists = array(); if ($handle = opendir('播放列表')) { 而(假!==($播放列表= readdir($handle))) { if ($playlist != “。” && $播放列表!=“..”){ array_push($plists, substr($playlist, 0, strripos($playlist, '.')-1)); } } } else { die('错误:无法打开 播放列表!'); } $arr = 数组(“条目”=>$plists); $json = json_encode($arr);回声 $json; } 别的 { die('错误:没有这样的动作!'); } ?>

它从array_push(... 行的中间开始。

我真的想不出它在做什么。它周围的任何地方都没有echos。有什么想法吗?

【问题讨论】:

    标签: php


    【解决方案1】:

    看起来=> 正在关闭您的 PHP 代码。您是否启用了短标签?还是某种自定义标签?

    【讨论】:

    • 啊。那有点奇怪。我用一个短标签开始它,所以我将它更改为常规标签并修复它。虽然我不确定为什么它会开始打印中间的代码......
    猜你喜欢
    • 2016-09-03
    • 1970-01-01
    • 2014-09-14
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-14
    • 2015-12-21
    相关资源
    最近更新 更多