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:[email protected],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:[email protected],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:[email protected],opinion=not at all,comment:your site are cool from:[email protected],opinion=he loves computer,comment:your site are waste. --------------------- can some one show me the way? thanks. Link to comment https://forums.phpfreaks.com/topic/217173-grab-data-from-text-file-after-char/ 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. Link to comment https://forums.phpfreaks.com/topic/217173-grab-data-from-text-file-after-char/#findComment-1127870 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? ... ?> Link to comment https://forums.phpfreaks.com/topic/217173-grab-data-from-text-file-after-char/#findComment-1127879 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 } } Link to comment https://forums.phpfreaks.com/topic/217173-grab-data-from-text-file-after-char/#findComment-1127891 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.. Link to comment https://forums.phpfreaks.com/topic/217173-grab-data-from-text-file-after-char/#findComment-1127910 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.