Php 从输出中删除空白行
我有一个为谷歌购物创建XML文档的代码。谷歌被挂在一个空行上。我不知道如何把线去掉。代码来自Magento Commerce数据库Php 从输出中删除空白行,php,xml,google-shopping,Php,Xml,Google Shopping,我有一个为谷歌购物创建XML文档的代码。谷歌被挂在一个空行上。我不知道如何把线去掉。代码来自Magento Commerce数据库 <?php echo '<?xml version="1.0" ?>'; ?> <rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:c="http://www.base.google.com/cns/1.0"> <channel> <t
<?php echo '<?xml version="1.0" ?>'; ?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:c="http://www.base.google.com/cns/1.0">
<channel>
<title>Spray Foam Systems</title>
<link>http://www.sprayfoamsys.com/store/</link>
<description>Spray Foam Rigs, Spray Foam Equipment, Sprayfoam Parts and Supplies.</description>
<?php
$con = mysql_connect(REMOVED) or die(mysql_error());
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sprayfoa_store", $con);
$query = mysql_query("SELECT * FROM `catalog_product_flat_1` WHERE `visibility` = 4 ORDER BY entity_id ASC")
or die(mysql_error());
?>
<?php
while($row = mysql_fetch_array($query))
{
?>
<item>
<g:id><?php echo $row['entity_id']; ?></g:id>
<title><?php echo $row['name']; ?></title>
<description><?php echo $row['short_description']; ?></description>
<g:google_product_category>Business & Industrial > Construction</g:google_product_category>
<g:product_type>Spray Foam Parts & Supplies > Fusion AP Parts</g:product_type>
<link>http://sprayfoamsys.com/store/<?php echo $row['url_path']; ?></link>
<g:image_link>http://sprayfoamsys.com/store/media/catalog/product<?php echo $row['small_image']; ?></g:image_link>
<g:condition>new</g:condition>
<g:availability>in stock</g:availability>
<g:price><?php echo $row['price']; ?></g:price>
<g:brand>
<?php
$entity_id = $row['entity_id'];
$query2 = mysql_query("SELECT * FROM `catalog_product_entity_varchar` WHERE entity_id = '$entity_id' AND attribute_id = '127'")
or die(mysql_error());
while($row2 = mysql_fetch_array($query2))
{
echo $row2['value'];
} ?>
</g:brand>
<g:mpn><?php echo $row['sku']; ?></g:mpn>
</item>
<?php
}
mysql_close($con);
?>
</channel>
</rss>
喷射泡沫系统
http://www.sprayfoamsys.com/store/
采购产品喷雾泡沫钻机,喷雾泡沫设备,喷雾泡沫零件和用品。
工商及科技局;工业建设
喷涂泡沫零件及配件;提供融合AP部件
http://sprayfoamsys.com/store/
http://sprayfoamsys.com/store/media/catalog/product
新的
有现货的
你可以试着像这样去掉新词
<description><?php echo str_replace(array("\r\n", "\n"), ' ', $row['short_description']); ?></description>
请参阅PHP手册中的函数。您可以尝试此函数
function removeSpaces($buffer){
$buffer = str_replace(array('\n', '\r'), array('', ''), $data);
return $buffer;
}
@ob_start("ob_gzhandler");
@ob_start("removeSpaces");
把它放在任何php页面上,它就会解决您的问题。函数将删除字符串开头和结尾的空白。如果要删除字符串中任何位置的换行符,可以执行以下操作:
[...snip...]
echo $row2['value'];
} ?></g:brand> <---closing tag up against closing PHP tag
<g:mpn><?php echo $row['sku']; ?></g:mpn>
</item>
<?php <---eliminated blank lines before php tag
}
mysql_close($con);
?>
[...snip...]
str_replace(数组(“\n”,“\r\n”),“,$row['short_description'];);
如果你对数据如何存储在数据库中有控制权,我会考虑用类似的函数“清洗”输入,这样你就不必把这个页面弄乱了。
你可以把它变成这样的:
[...snip...]
echo $row2['value'];
} ?></g:brand> <---closing tag up against closing PHP tag
<g:mpn><?php echo $row['sku']; ?></g:mpn>
</item>
<?php <---eliminated blank lines before php tag
}
mysql_close($con);
?>
[...snip...]
[…剪断…]
echo$row2['value'];
} ?>
[…剪断…]