2012-01-31 2 views
0

Google 쇼핑을위한 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> 
<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 &amp; Industrial &gt; Construction</g:google_product_category> 
<g:product_type>Spray Foam Parts &amp; Supplies &gt; 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> 

가 출력 보이는 : 첫 번째 항목이 설명 태그는 빈 줄, 그러나 두 번째 항목이 없습니다로 문제없이 통과

<item> 
<g:id>15</g:id> 
<title>DK 817 - Gun Cleaning Solvent and Lubricator - Aerosol Can 16 oz. </title> 
<description>DK 817 is a cleaner-lubricant used on for cleaning polyurethane dispensing equipment and guns. DK817 comes in a 16 oz. aerosol can. Contractors praise it's ability to quickly clean components with uncured polyurethane materials. </description> 
<g:google_product_category>Business &amp; Industrial &gt; Construction</g:google_product_category> 
<g:product_type>Spray Foam Parts &amp; Supplies &gt; Fusion AP Parts</g:product_type> 
<link>http://sprayfoamsys.com/store/dk-817-gun-cleaning-solvent-and-lubricator-aerosol-can.html</link> 
<g:image_link>http://sprayfoamsys.com/store/media/catalog/product/d/k/dk817.jpg</g:image_link> 
<g:condition>new</g:condition> 
<g:availability>in stock</g:availability> 
<g:price>24.9900</g:price> 
<g:brand>brand 
</g:brand> 
<g:mpn>partnumber</g:mpn> 
</item> 


<item> 
<g:id>16</g:id> 
<title>Allegro Full Mask SAR Replacement Lens 9901-09L</title> 
<description>Replacement lens for the 9901 Series Allegro Full Face Mask. Clear, scratch resistant lens. Easy to replace. Lens only. 

Allegro 9901-09L</description> 
<g:google_product_category>Business &amp; Industrial &gt; Construction</g:google_product_category> 
<g:product_type>Spray Foam Parts &amp; Supplies &gt; Fusion AP Parts</g:product_type> 
<link>http://sprayfoamsys.com/store/allegro-full-mask-sar-replacement-lens-9901-09r.html</link> 
<g:image_link>http://sprayfoamsys.com/store/media/catalog/product/a/l/al-9901-09l-1.jpg</g:image_link> 
<g:condition>new</g:condition> 
<g:availability>in stock</g:availability> 
<g:price>75.0000</g:price> 
<g:brand> 
Allegro</g:brand> 
<g:mpn>9901-09L</g:mpn> 
</item> 

, 유일한 오류를 포맷 나에게 XML을 제공 설명 태그의 빈 줄이의 내가 생각할 수있는

답변

3

<description><?php echo str_replace(array("\r\n", "\n"), ' ', $row['short_description']); ?></description> 
처럼 줄 바꿈을 제거 시도 할 수

PHP 설명서의 str_replace() 함수를 참조하십시오.

-1

당신은

function removeSpaces($buffer){ 
    $buffer = str_replace(array('\n', '\r'), array('', ''), $data); 
    return $buffer; 
} 

@ob_start("ob_gzhandler"); 
@ob_start("removeSpaces"); 

어떤 PHP 페이지의 상단에 넣어이 기능을 시도 할 수 있으며

0

trim() 함수는의 시작과 끝에서 공백을 제거하여 문제가 알아서 할게요 끈. 당신이 문자열 어디서나 발생하는 행 구분을 제거하려는 경우, 당신은 같은 것을 할 수 있습니다 : 당신이 데이터가 데이터베이스에 저장되는 방식에 대한 제어가있는 경우

str_replace(array("\n","\r\n"), "", $row['short_description'];);

, 내가 고려할 것 " 비슷한 기능으로 입력을 "청소"하므로이 페이지를 어수선하게 정리할 필요가 없습니다.

0

당신은 이런 식으로 변경할 수 있습니다 :

[...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...]