-1

i want to create xml file with php ...

How can I jump line? with br or \ n?

I try it every time.

can anyone help me?

include "ayar.php";
$myFile = "rss.xml";
$fh = fopen($myFile, 'w') or die("can't open file");



$rss_txt .= '<?xml version="1.0"?>';
$rss_txt .= '<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">';
$rss_txt .= '<channel>';

 while($values_query = mysql_fetch_assoc($query))
 {
        $rss_txt .= '<item>';
        $rss_txt .= '<g:title>' .$values_query['baslik']. '</g:title><br />';
        $rss_txt .= '<g:description>' .$values_query['aciklama']. '</g:description><br />';
        $rss_txt .= '<g:link>' .$values_query['resim1k']. '</g:link><br />';
        $rss_txt .= '<g:image_link>' .$values_query['resim1k']. '</g:image_link><br />';    
        $rss_txt .= '</item>';

 }
$rss_txt .= '</channel>';
$rss_txt .= '</rss>';

fwrite($fh, $rss_txt);
fclose($fh);
1

2 Answers 2

0

As RockwoodON did state correctly, a <br /> is not the way to go here. <br /> is a tag for HTML renderers to render a newline. To format your XML you will need line break characters/strings, which are unfortunately not platform independent.

Every platform has its line breaks

  • Windows hat Carriage Return plus linefeed ("\r\n")
  • *nix (excluding macOS) has a single linefeed "\n"
  • macOS has a single carriage return "\r"

Having said that, most modern editors might recognize several/all of those options. notepad++ does, VS too, just to mention two. So the choice of line breaks should depend on your target system/editor or use-case respectively.

If the system your code runs on is the same as the target platform, you might use PHP_EOL (see here), but it's only useful as long as you are not switching platforms on either side. But you should really think about defining you own constant, to stay consistent withing your file

define('EOL',   '\r\n');

// ...

$rss_txt .= '<item>';
$rss_txt .= '<g:title>' .$values_query['baslik']. '</g:title>'.EOL;
$rss_txt .= '<g:description>' .$values_query['aciklama']. '</g:description>'.EOL;
$rss_txt .= '<g:link>' .$values_query['resim1k']. '</g:link>'.EOL;
$rss_txt .= '<g:image_link>' .$values_query['resim1k']. '</g:image_link>'.EOL;    
$rss_txt .= '</item>';
Sign up to request clarification or add additional context in comments.

Comments

0

An HTML line break sequence is definitely not right. I believe you need to use a 'carriage return' (CR) which could be written in your string as \r

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.