在Content-Type:text / plain中删除不需要的行

时间:2014-11-12 20:54:19

标签: php text content-type removing-whitespace

我将用代码描述我的问题 - 这将是最好的。

<?
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. 与DB的连接
  3. 从DB获取数据
  4. 重要提示:将标题设置为Content-Type:text / plain
  5. 重要信息:使用echo
  6. 打印文本数据

    结果:

    **!!! 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内部的echo生成的数据行,但没有7行。

    问题:

    如何做到这一点,什么时候(等)去掉那些不需要的线?

    谢谢。

2 个答案:

答案 0 :(得分:1)

ob_clean();将与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'];  
}

那应该从包含的文件中删除任何不需要的额外空格。

答案 1 :(得分:0)

空白行不是来自神秘的未知。他们在你的代码中的某个地方。在打开PHP标记之前和关闭PHP标记之后检查您的文件(包括您包含/要求的文件)的空格。该空格将被传递给浏览器。

相关问题