Adding Line Break in XML Contained in PHP -


i creating xml rss feed using php pull in data database. therefore, xml contained in php. want add line breaks between every 1 of these variables in <description> :

echo '<item>'; echo '<title>' . $product_name . '</title>'; echo ' <link>http://www.....com</link>'; echo '<description>' . $product_line . ' ' . $product_scale . ' ' . $product_vendor . ' ' . $product_description . ' $' . $buy_price . '</description>'; echo '</item>'; 

i have tried adding <br > , "<br />" after every variable in <description> tag keeps of xml/rss data running on page.

i know can add <xml> tags format here different since xml being echoed in php. there way around adding line breaks in xml contained in php echo?

here entire script if needed:

<?php header('content-type: text/xml'); ?> <?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>      <rss version="2.0" xmlns:atom="http://www.w3.org/2005/atom">         <channel>             <title>classic cars rss</title>             <atom:link href="http://<?= $_server['http_host'].$_server['php_self'] ?>" rel ="self" type="application/rss+xml" />             <description>classic cars rss feed learning php</description>             <lastbuilddate><?= $builddate ?></lastbuilddate>             <language>en-us</language>         <?php          define('db_location', 'x');         define('db_username', 'x');         define('db_pass', 'x');         define('db_name', 'x');          $dbc = mysqli_connect(db_location, db_username, db_pass, db_name)             or die('error connecting database');          $query = "select productname, productline, productscale, productvendor, productdescription, buyprice products `productline` = 'vintage cars' or `productline` = 'trains'";         $result = mysqli_query($dbc, $query)                 or die('error querying request');                    while ($row = mysqli_fetch_array($result)) {                      $product_name = $row['productname'];                     $product_line = $row['productline'];                     $product_scale = $row['productscale'];                     $product_vendor = $row['productvendor'];                     $product_description = $row['productdescription'];                     $buy_price = $row['buyprice'];              echo '<item>';             echo '<title>' . $product_name . '</title>';             echo ' <link>http://www.test.ishabagha.com</link>';             echo '<description>' . $product_line . ' ' . $product_scale . ' ' . $product_vendor . ' ' . $product_description . ' $' . $buy_price . '</description>';             echo '</item>';            }         ?>              </channel>         </rss> 

you can use single echo line breaks:

echo 'line1 line2'; 

alternatively use \n

echo "line1\nline2"; //you need doublequotes when using \n 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -