简体   繁体   English

在Content-Type:文本/纯文本时删除不需要的行

[英]Remove unwanted lines while 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 重要说明:将标题设置为Content-Type:文本/纯文本
  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. -预期是for中回显生成的数据行,但没有那7行。

QUESTION: 题:

How to do that, what to call when (etc.) to get rid of those unwanted lines? 如何做到这一点,当(例如)摆脱那些多余的线路时该怎么称呼?

Thank you. 谢谢。

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

That should get rid of any unwanted extra whitespace from included files. 那应该摆脱包含文件中多余的多余空格。

The blank lines don't come from the mysterious unknown. 空行不是来自神秘的未知。 They're in your code somewhere. 它们在您的代码中的某个地方。 Check your files (including the files you include/require) for whitespace before your opening PHP tags and after your closing PHP tags. 在打开PHP标记之前和关闭PHP标记之后,请检查文件(包括您包含/需要的文件)中的空格。 That whitespace will be passed to the browser. 该空格将传递给浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM