How to split a space separated file?
Posted
by simplesimon
on Stack Overflow
See other posts from Stack Overflow
or by simplesimon
Published on 2010-06-15T07:29:55Z
Indexed on
2010/06/15
7:32 UTC
Read the original article
Hit count: 350
Hi I am trying to import this:
http://en.wikipedia.org/wiki/List_of_countries_by_continent_%28data_file%29
which is of the format like:
AS AF AFG 004 Afghanistan, Islamic Republic of
EU AX ALA 248 Åland Islands
EU AL ALB 008 Albania, Republic of
AF DZ DZA 012 Algeria, People's Democratic Republic of
OC AS ASM 016 American Samoa
EU AD AND 020 Andorra, Principality of
AF AO AGO 024 Angola, Republic of
NA AI AIA 660 Anguilla
if i do
<? explode(" ",$data"); ?>
that works fine apart from countries with more than 1 word.
how can i split it so i get the first 4 bits of data (the chars/ints) and the 5th bit of data being whatever remains?
this is in php
thank you
© Stack Overflow or respective owner