Stooney Posted November 21, 2006 Share Posted November 21, 2006 im reading from a textfile, and building an array with the data. ex of text file:[code]|AEther Flash|,|7th Edition|,|Red|,|Enchantment|,|2RR|,|n/a|,| Whenever a creature comes into play, AEther Flash deals 2 damage to it.|,|As the foul beast appeared, arcane lightning crackled around it.#172|,|Wayne England|,|Uncommon|,0,7130[/code]that is one of many thousand lines in the file.what i need to do is take this and build an array with it. each element of the array will contain the text in between the ||. So in the above example, array element 0 would be 'Aether Flash', 1 would be 7th Edition, and so on. thnx in advance for the help :D Link to comment https://forums.phpfreaks.com/topic/27924-split-strings-text-between-characters/ Share on other sites More sharing options...
hitman6003 Posted November 21, 2006 Share Posted November 21, 2006 [code]$filename = "path/to/file.txt";$file = file($filename);$data = array();foreach ($file as $line) { $data[] = explode("|,|",$line);}echo '<pre>';print_r($data);echo '</pre>';[/code] Link to comment https://forums.phpfreaks.com/topic/27924-split-strings-text-between-characters/#findComment-127702 Share on other sites More sharing options...
Stooney Posted November 21, 2006 Author Share Posted November 21, 2006 thnx a bunch. i cant believe i didn't see that -_- closest i got was explode(",", $data); until i realized there were more commas than just those separating the data. Link to comment https://forums.phpfreaks.com/topic/27924-split-strings-text-between-characters/#findComment-127708 Share on other sites More sharing options...
kenrbnsn Posted November 21, 2006 Share Posted November 21, 2006 You should also look at the function [url=http://www.php.net/fgetcsv]fgetcsv()[/url] which will read your file, explode each line in one function.Ken Link to comment https://forums.phpfreaks.com/topic/27924-split-strings-text-between-characters/#findComment-127770 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.