dtgta48604 2014-11-12 20:54
浏览 375
已采纳

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

I will describe my problem with code - it would be the best.

<?
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'];  
}

What is happening:

  1. include some stuff
  2. connection to DB
  3. get data from DB
  4. IMPORTANT: set header as Content-Type: text/plain
  5. IMPORTANT: print text data with echo

Result:

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

Expected result:

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

- Expected is lines of data generated by echo inside the for, but without that 7 lines.

QUESTION:

How to do that, what to call when (etc.) to get rid of those unwanted lines?

Thank you.

  • 写回答

2条回答 默认 最新

  • douchao0358 2014-11-12 20:56
    关注

    ob_clean(); will clear out the output buffer, in conjuction with 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'];  
    }
    

    That should get rid of any unwanted extra whitespace from included files.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line