Slim 3.3 輸出中缺少字符 (Slim 3.3 missing characters in output)


問題描述

Slim 3.3 輸出中缺少字符 (Slim 3.3 missing characters in output)

我正在嘗試讓 Slim 在我的 Windows 7 系統上運行。到目前為止,我已經用 Composer 安裝了所有東西,但是當我運行一個非常簡單的程序時,輸出與預期不符。

下面是我的代碼:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

use Slim\App;
use Slim\Http\Request;
use Slim\Http\Response;

require '../vendor/autoload.php';

$app = new App;

$app‑>get('/', function (Request $in, Response $out, $args) {
 return $out‑>write("xxxxx");
});

$app‑>run();

我期待輸出“xxxxx”,而不是“x”。

這意味著我在某處丟失了 4 個字符。運行 PHP 5.5.12 編碼是 UTF‑8(不是 BOM)

當我運行 "curl ‑v http ://localhost:8080/"

我得到

D:\wamp\www\slim_test\src\public>curl ‑v http://localhost:8080/
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User‑Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Host: localhost:8080
< Connection: close
< X‑Powered‑By: PHP/5.5.12
< Content‑Type: text/html; charset=UTF‑8
< Content‑Length: 5
<

x* Closing connection 0

感謝您的幫助。

編輯 一旦我將這些代碼行附加到文件末尾,響應是正確的。


參考解法

方法 1:

This issue has been solved as I found a very stupid mistake.

I had 2 blank spaces before the <?php tag.

(by StefanStefan)

參考文件

  1. Slim 3.3 missing characters in output (CC BY‑SA 2.5/3.0/4.0)

#php-5.5 #response #slim-3






相關問題

當作為參數傳遞時,PHP 如何解釋和評估函數和匿名函數? (How does PHP interpret and evaluate function and anonymous function when passed as an argument?)

使用 symfony 時 PHP 5.5 無法識別服務器 (PHP 5.5 won't recognise server when using symfony)

升級到 PHP5.5 時 Wordpress 崩潰 (Wordpress crashes when upgrading to PHP5.5)

從數據庫返回多個值 (return multiple values from database)

PHP:嵌套 foreach 循環的問題 (PHP: Issue with nested foreach loops)

如果條件在幾小時、幾天內不起作用 (if condition not working for Hours,Days)

Slim 3.3 輸出中缺少字符 (Slim 3.3 missing characters in output)

PHP排序對象值但保留原始相對順序 (PHP sort objects value but retain original relative order)

遇到錯誤無法加載請求的文件:helpers/form_validation_helper.php (An Error Was Encountered Unable to load the requested file: helpers/form_validation_helper.php)

如何從類的函數內部訪問全局變量 (How to access global variable from inside class's function)

如何修改輸出緩衝區? (How to modify output buffer?)

在同一台 Ubuntu 服務器上安裝和配置 PHP5 和 7 (Install and configure PHP5 and 7 on same Ubuntu server)







留言討論