Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

writing to a new line in text file

General discussions related to php

Moderators: macek, egami, gesf

writing to a new line in text file

Postby dd09 » Thu Jul 05, 2012 6:48 am

$str=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

i want to print the above $str content like the below in the text file ...please help with it....
i m using the following code

file_put_contents('BBB.txt',$str);

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
dd09
New php-forum User
New php-forum User
 
Posts: 34
Joined: Wed Jan 11, 2012 10:01 pm

Re: writing to a new line in text file

Postby johnj » Fri Jul 06, 2012 11:58 pm

use strpos() to find the position of TITLE 2 and TITLE 3 and then extract that string using substr().
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: writing to a new line in text file

Postby dd09 » Mon Jul 09, 2012 4:52 am

thanks john for ur reply

i have already parsed the title section from the text file ....
but while storing in another text file it is passed as a string.

text file from which i m parsing is...

HEADER DNA-RNA HYBRID 05-DEC-94 100D
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
COMPND MOL_ID: 1;


here is the code.....

Code: Select all
<?php
session_start();
?>
<?php
$_SESSION['']="";
$str='';
$line='';
//$pdb = file_get_contents($_SESSION['pdb']);
//echo $_SESSION['pdb'];
$files = $_SESSION['pdb'];

$afile=explode("\n",$files);
  foreach($afile as $line)
   {
    if (preg_match('/^TITLE.*.$/',$line))
   {
   echo "<pre>$line</pre>"; 
     $str.=$line; 
     }
   }
   unset($line);
   file_put_contents('BBB.txt',$string);
 ?>
dd09
New php-forum User
New php-forum User
 
Posts: 34
Joined: Wed Jan 11, 2012 10:01 pm


Return to PHP General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.