writing to a new line in text file

General discussions related to php

Moderators: egami, macek, gesf

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

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

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

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().

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

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);
 ?>

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest