簡體   English   中英

在Content-Type:文本/純文本時刪除不需要的行

[英]Remove unwanted lines while Content-Type: text/plain

我將用代碼描述我的問題-那將是最好的。

<?
include('configs.php');  
require_once 'DBQueries.php'; 
$con = mysql_connect( $db_host, $db_user, $db_pass );
mysql_query("SET NAMES 'cp1250'") or die('Could not set names');     
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  } 
mysql_select_db($db_dbname);     
$oUnexportedOrders = DBQueries::getInstance()->getUnexportedOrders();
header("Content-Type: text/plain");         
while ($aOrderExport = mysql_fetch_assoc ($oUnexportedOrders)){
    echo $aOrderExport['data'];  
}

怎么了:

  1. 包括一些東西
  2. 與數據庫的連接
  3. 從數據庫獲取數據
  4. 重要說明:將標題設置為Content-Type:文本/純文本
  5. 重要提示:打印帶有回顯的文本數據

結果:

**!!! There are 7 unwanted lines !!!**
line of data
line of data 
line of data
line of data
....

預期結果:

line of data
line of data 
line of data
line of data

-預期是for中回顯生成的數據行,但沒有那7行。

題:

如何做到這一點,當(例如)擺脫那些多余的線路時該怎么稱呼?

謝謝。

ob_clean(); ob_start();結合使用將清除輸出緩沖區ob_start();

<?
ob_start();
include('configs.php');  
require_once 'DBQueries.php'; 
$con = mysql_connect( $db_host, $db_user, $db_pass );
mysql_query("SET NAMES 'cp1250'") or die('Could not set names');     
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  } 
mysql_select_db($db_dbname);     
$oUnexportedOrders = DBQueries::getInstance()->getUnexportedOrders();
ob_clean();
header("Content-Type: text/plain");         
while ($aOrderExport = mysql_fetch_assoc ($oUnexportedOrders)){
    echo $aOrderExport['data'];  
}

那應該擺脫包含文件中多余的多余空格。

空行不是來自神秘的未知。 它們在您的代碼中的某個地方。 在打開PHP標記之前和關閉PHP標記之后,請檢查文件(包括您包含/需要的文件)中的空格。 該空格將傳遞給瀏覽器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM