new line problem

General discussions related to php

Moderators: macek, egami, gesf

dd09
New php-forum User
New php-forum User
Posts: 34
Joined: Wed Jan 11, 2012 10:01 pm

new line problem

Postby dd09 » Tue Jul 03, 2012 9:24 am

below is the code which parse the TITLE section from the title.txt file and put it into the
BBB.txt file.... but the problem is while storing parsing content it is storing in one line and not one
below the other.

consider that $_SESSION['pdb'] is title.txt file....

title.txt file

COMPND MOL_ID: 1;
COMPND 2 MOLECULE: DNA/RNA (5'-R(*CP*)-D(*CP*GP*GP*CP*GP*CP*CP*GP*)-
COMPND 3 R(*G)-3');
COMPND 4 CHAIN: A, B;
COMPND 5 ENGINEERED: YES
TITLE CRYSTAL STRUCTURE OF THE HIGHLY DISTORTED CHIMERIC DECAMER
TITLE 2 R(C)D(CGGCGCCG)R(G)-SPERMINE COMPLEX-SPERMINE BINDING TO
TITLE 3 PHOSPHATE ONLY AND MINOR GROOVE TERTIARY BASE-PAIRING


Code: Select all

<p id='atom'><a href='download.php'>TITLE_Download</a></p>

<?php
session_start();
?>
<?php
$_SESSION['']="";
$str='';
$line='';
$files = $_SESSION['pdb'];
$afile=explode("\n",$files);
foreach($afile as $line)
   {
    if (preg_match('/^TITLE.*.$/',$line))
   {
   ?>
         
         <html>
         <table border="0" bgcolor="navyblue">
         <tr><td><?php echo "<pre>$line"?></td></tr>
         </table>
         </html>
<?PHP
      $str.=$line;
   }
   }
   unset($line);
   file_put_contents('BBB.txt',$str);
?>

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: new line problem

Postby johnj » Sat Jul 07, 2012 12:04 am

add "\n" or "<br/>" after each line depending on where you are going to display this text.

dd09
New php-forum User
New php-forum User
Posts: 34
Joined: Wed Jan 11, 2012 10:01 pm

Re: new line problem

Postby dd09 » Tue Jul 10, 2012 7:45 am

could u please tell me where to put "\n" or "<br/>"....

iam4423
New php-forum User
New php-forum User
Posts: 50
Joined: Fri Jan 20, 2012 8:00 am

Re: new line problem

Postby iam4423 » Tue Jul 10, 2012 12:56 pm

from what i can tell you need to change

Code: Select all

$str.=$line;
to

Code: Select all

$str.=$line."\n";

tkdbb84
New php-forum User
New php-forum User
Posts: 137
Joined: Tue Mar 08, 2011 9:25 am

Re: new line problem

Postby tkdbb84 » Wed Jul 11, 2012 8:50 am

if you a writing to a file; you should use the constant PHP_EOL it will give you the correct newline for the OS you are using

Code: Select all

$str .= $line.PHP_EOL;

dd09
New php-forum User
New php-forum User
Posts: 34
Joined: Wed Jan 11, 2012 10:01 pm

Re: new line problem

Postby dd09 » Wed Jul 11, 2012 12:48 pm

thanks tkdbb84 and iam224.... it worked ...
thanks a lot... :D

iam4423
New php-forum User
New php-forum User
Posts: 50
Joined: Fri Jan 20, 2012 8:00 am

Re: new line problem

Postby iam4423 » Thu Jul 19, 2012 9:07 am

no problem, glad i could belp but i am not 224 ¬¬


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest