vidyashankara Posted June 9, 2006 Share Posted June 9, 2006 Here's a Text File.[code]HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#[/code]@#!@# can be any number/letter or anything. The script should read this file, come up with this outputThe file has 2 unique HETATM's, they are HOH and AC9. Some text files might have just HOH or just AC9 or neither, They might have something else. Any way out? Quote Link to comment https://forums.phpfreaks.com/topic/11591-reading-text-file-only-certain-columns/ Share on other sites More sharing options...
poirot Posted June 9, 2006 Share Posted June 9, 2006 I believe I coded something like that for you before. It is here:[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95300\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=95300[/a]A slight modification:[code]<?php$str = 'HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#';// If you want to retrieve the values from a file, use this:// $str = file_get_contents('file.txt');$array = explode("\n", $str);for ($i=0; $i<count($array); $i++) { preg_match_all("/([^ \r\n]+)(?:[ ]+)*/", $array[$i], $m); $matches[$i] = $m[1]; $fifth[$i] = $m[1][4];}echo '<pre>';print_r($matches);echo '</pre>';?>[/code]$matches is an array and should be something like this:[code]Array( [0] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [1] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [2] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [3] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [4] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [5] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [6] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [7] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => AC9 [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [8] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => AC9 [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [9] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => AC9 [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [10] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => AC9 [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [11] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => AC9 [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ))[/code]What is easy enough to work with I believe. Quote Link to comment https://forums.phpfreaks.com/topic/11591-reading-text-file-only-certain-columns/#findComment-43721 Share on other sites More sharing options...
vidyashankara Posted June 9, 2006 Author Share Posted June 9, 2006 [!--quoteo(post=381936:date=Jun 9 2006, 12:47 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 9 2006, 12:47 PM) [snapback]381936[/snapback][/div][div class=\'quotemain\'][!--quotec--]I believe I coded something like that for you before. It is here:[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95300\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=95300[/a]A slight modification:[code]<?php$str = 'HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# HOH !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#HETATM @#!@# !@#!@# !@#!@# AC9 !@#!@# !@#!@# !@#!@#';// If you want to retrieve the values from a file, use this:// $str = file_get_contents('file.txt');$array = explode("\n", $str);for ($i=0; $i<count($array); $i++) { preg_match_all("/([^ \r\n]+)(?:[ ]+)*/", $array[$i], $m); $matches[$i] = $m[1]; $fifth[$i] = $m[1][4];}echo '<pre>';print_r($matches);echo '</pre>';?>[/code]$matches is an array and should be something like this:[code]Array( [0] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [1] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [2] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [3] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [4] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [5] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [6] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => HOH [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [7] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => AC9 [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [8] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => AC9 [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [9] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => AC9 [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [10] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => AC9 [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ) [11] => Array ( [0] => HETATM [1] => @#!@# [2] => !@#!@# [3] => !@#!@# [4] => AC9 [5] => !@#!@# [6] => !@#!@# [7] => !@#!@# ))[/code]What is easy enough to work with I believe.[/quote]Yeah the 2 scripts are similar. I couldnt figure out how to modify it. The last one was just one letter. I figured a 3 letter word might be complex. Hey, Thanks! I really appreciate your help! :) you rock! Quote Link to comment https://forums.phpfreaks.com/topic/11591-reading-text-file-only-certain-columns/#findComment-43737 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.