chole Posted October 29, 2010 Share Posted October 29, 2010 I have a text file that contain something like this : question.txt ------------------------ 12/10/2010 Quest : Was a web designer really care about your web security other than thinking so hard to design your web just based on how the web will looks like?. >>from:sombody@somwhere.com,opinion=not at all,comment:your site are cool 11/10/2010 Quest : Was a web designer really love his girl friend in other side they r almost got no time dating with her? >>from:sombody@somwhere.net,opinion=he loves computer,comment:your site are waste. ------------------------- All i need to do is, grabing all informations after the char ">>" and write it to another text file name "output.txt" that will contain : output.txt --------------------- from:sombody@somwhere.com,opinion=not at all,comment:your site are cool from:sombody@somwhere.net,opinion=he loves computer,comment:your site are waste. --------------------- can some one show me the way? thanks. Quote Link to comment Share on other sites More sharing options...
btherl Posted October 29, 2010 Share Posted October 29, 2010 There's two parts to that. Start with reading the file and outputting it exactly as it is. Then add a filter that outputs only lines with >> at the front. If you have a go at it then we can help when you get stuck. Quote Link to comment Share on other sites More sharing options...
chole Posted October 29, 2010 Author Share Posted October 29, 2010 <?php $myFile = "master.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh,filesize($myFile)); fclose($fh); //echo $theData; what kind of php filtering function i should use here? ... ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted October 29, 2010 Share Posted October 29, 2010 It's probably easier if you read the file line by line, with a loop like this: while ($line = fgets($fh)) { if (strpos($line, '>>') === 0) { # This is a matching line } } Quote Link to comment Share on other sites More sharing options...
chole Posted October 29, 2010 Author Share Posted October 29, 2010 thanks for the light btherl.. i'll do it in your way...it looks fine.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.