Gulsaes Posted October 31, 2008 Share Posted October 31, 2008 Hi i'm fairly noob to php, but since i'm becoming a php freak i thought this was the best site to get some help. I have an array that has lots of text. I'm wanting to break each section of text i want into several separate arrays. current array looks like this Array ( [0] => @ Date: 2008-10-31 - Time 08:55:00 Z @FAJS 310900Z 35012KT 320V040 CAVOK 27/10 Q1022 NOSIG=@FAJB 310800Z AUTO 35004KT //// // ////// 26/12 Q1021=@FALA 310900Z 36017KT CAVOK 29/12 Q1019 RMK RECEIVED AT 08:54=@FAWB 310500Z 06010KT CAVOK 24/13 Q1019 RMK RECEIVED AT 06:05=@FAWK NIL=@FASK 310800Z 03010KT CAVOK 23/// Q1020=@FAPR 310800Z 07007KT CAVOK 19/05 Q1019=@FAIR 310800Z 36009KT CAVOK 26/13 Q1020=@FASI 310800Z AUTO 33007KT //// // ////// 25/15 Q1021=@FAGC 310800Z 33012KT CAVOK 25/11 Q1021 RMK RECEIVED AT 08:02=@FAGM 310900Z 36014KT CAVOK 26/11 Q1021 NOSIG RMK RECEIVED AT 08:52=@FAVV 310800Z AUTO 35006KT //// // ////// 27/12 Q1018=@ @FAPP 310800Z 04009KT 9999 FEW040 25/15 Q1020=@FALM 310800Z 09010KT 8000 FEW013 24/// Q1019=@FAHS 310800Z AUTO 11009KT //// // ////// 25/19 Q1014=@FAPH 310800Z AUTO 13005KT //// // ////// 25/18 Q1018=@FATZ 310800Z AUTO 18002KT //// // ////// 21/17 Q1020=@FATI 310600Z AUTO 02006KT //// // ////// 31/10 Q1016=@FAER 310800Z AUTO 04007KT //// // ////// 32/12 Q1016=@FATH 310800Z 16003KT 9999 BKN020 24/19 Q1017=@ @FAMM 310800Z 24004KT 9999 FEW040 30/05 Q1017=@FALI 310800Z AUTO 33009KT //// // ////// 30/M00 Q1018=@FAKD 310800Z AUTO 03001KT //// // ////// 29/06 Q1017=@FARG 310900Z AUTO 34005KT //// // ////// 31/10 Q1015=@FAPN 310700Z AUTO 03004KT //// // ////// 30/10 Q1017 RMK RECEIVED AT 07:14=@FAPS 310800Z AUTO 01007KT //// // ////// 29/// Q1017=@@FANS 310800Z AUTO 06006KT //// // ////// 18/18 Q1020=@FAKN 310800Z 08007KT 0100 -DZFG OVC001 18/18 Q1021 NOSIG=@FAEO 310800Z 03013KT 9999 SCT015 22/13 Q1024=@FASR 310800Z AUTO /////KT //// // ////// 25/12 Q1020=@FAWI 310800Z AUTO 02009KT //// // ////// 24/14 Q1024=@@FADN 310830Z 11009KT 080V160 9999 FEW030 23/16 Q1017 NOSIG=@FAVG 310800Z AUTO 10004KT //// // ////// 22/14 Q1017=@FAMG 310800Z AUTO 11005KT //// // ////// 23/16 Q1018=@FAPM 310800Z 09010KT CAVOK 20/10 Q1018 RMK RECEIVED AT 08:20=@FAGY 310800Z AUTO 03006KT //// // ////// 19/15 Q1019=@FALY 310800Z AUTO 09002KT //// // ////// 21/12 Q1019=@FANC 310800Z AUTO 07003KT //// // ////// 22/17 Q1019=@FAVY NIL=@FARB 310800Z 21006KT 8000 SCT020 BKN050 25/20 Q1017 RMK RECEIVED AT 08:05=@FAUL 310800Z AUTO 07003KT //// // ////// 20/12 Q1019=@FAMX 310800Z AUTO 19002KT //// // ////// 20/17 Q1018=@@FABL 310800Z 35009KT CAVOK 26/03 Q1018 NOSIG=@FABM 310800Z 04007KT CAVOK 21/12 Q1021=@FAWM 310600Z AUTO 06010KT //// // ////// 21/12 Q1019=@FAHV 310600Z AUTO 07005KT //// // ////// 18/09 Q1017=@ @FAKM 310800Z 26001KT CAVOK 27/M03 Q1017=@FAUP 310800Z 15002KT CAVOK 29/M06 Q1015=@FASS 310800Z AUTO 36002KT //// // ////// 29/M07 Q1017=@FASB 310800Z 08002KT CAVOK 26/M06 Q1017=@FAAB 310800Z AUTO 22006KT //// // ////// 15/10 Q1015=@FACV 310800Z 35002KT CAVOK 23/M06 Q1016=@FADY 310800Z 34002KT CAVOK 25/06 Q1017=@ @FACT 310900Z 26005KT 190V320 CAVOK 22/12 Q1014 NOSIG=@FAGG 310900Z 13010KT 9999 FEW025 19/12 Q1015=@FALW 310600Z AUTO 24003KT //// // ////// 14/12 Q1014=@FAOB NIL=@FABY 310900Z AUTO 12003KT //// // ////// 22/08 Q1014=@FAPG 310800Z AUTO 09005KT //// // ////// 19/// Q1016=@ @FAPE 310830Z 12006KT 070V190 CAVOK 21/13 Q1016 NOSIG=@FAEL 310900Z 11009KT 080V140 9999 SCT023 BKN048 21/14 Q1016=@FAUT 310800Z 11007KT CAVOK 21/11 Q1018=@@FDMS 310800Z 00000KT 4000 -DZFG SCT008 OVC025 17/17 Q1020 @ NOSIG=@@FXMM 310900Z 36008KT CAVOK 27/04 Q1021 NOSIG=@@FBSK 310800Z 36003KT CAVOK 31/10 Q1016 NOSIG=@FBMN 310800Z 06013KT CAVOK 35/09 Q1015=@FBFT 310800Z 07007KT CAVOK 35/13 Q1016=@FBGZ NIL=@FBJW NIL=@FBKE 310800Z 18006KT CAVOK 29/12 Q1017=@FBMP NIL=@FBPA NIL=@FBTE NIL=@FBTS NIL=@FBSN NIL=@FBSP 310800Z 09014KT CAVOK 34/13 Q1016=@FBSW NIL=@FBLT NIL=@@FYWH 310900Z AUTO 05004KT //// // ////// 30/M00 Q1023=@FYWW 310800Z 26003KT CAVOK 28/02 Q1022=@FYKT 310800Z 00000KT CAVOK 26/03 Q1017=@FYWB 310800Z /////KT //// ////// ///// Q////=@FYGF 310800Z 19004KT CAVOK 30/02 Q1012=@FYLZ 310800Z AUTO 18009KT //// // ////// 19/10 Q1013=@FYOA 310800Z /////KT //// ////// ///// Q////=@@FQMA 310900Z 14004KT 110V220 9999 SCT018 BKN025 27/20 Q1016 NOSIG=@FQBR 310800Z 13009KT 100V160 9999 SCT017 30/21 Q1014=@FQNP 310800Z 03007KT 9999 BKN020 31/18 Q1016=@FQIN 310800Z 36003KT 9999 BKN020 27/22 Q1015=@FQLC 310800Z 05011 9999 BKN012 24/18 Q1021=@FQPB 310800Z 07009KT FEW020 FEW025CB 29/22 Q1015 RMK CB TO S/W=@FQQL 310800Z 00000KT CAVOK 32/17 Q1014=@FQTE NIL=@FQTT 310800Z 14008KT 9999 FEW020 33/23 Q1012=@FQVL NIL=@@FVHA 310800Z NIL=@FVBU 310800Z NIL=@FVTL 310800Z NIL=@FVCZ 310800Z NIL=@FVKB 310800Z NIL=@FVFA 310800Z NIL=@FVWN 310800Z NIL=@ @FWKI 310700Z 09012KT 9999 FEW022 25/17 Q1020 NOSIG=@FWCL 310700Z NIL=@FLLS 310800Z 06007KT CAVOK 29/10 Q1019NOSIG=@FLND 310400Z 07002KT 8000 FU SKC 17/11 Q1018=@FNLU NIL=@ @ ) want i'm wanting is to get the text between the @ and store them into seperate arrays and use the first 4 characters of each line between the @ ie. FAJS as the array name any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/130853-get-text-string-between-two-characters/ Share on other sites More sharing options...
feidakila Posted October 31, 2008 Share Posted October 31, 2008 Check these functions in the php manual array explode ( string $delimiter , string $string [, int $limit ] ) and substr function but I guess something like the code below should help... <?php $array_result = explode ("@", $your_array['the_string_to_analyze'],); foreach ($array_result as $key => $value) { $array_name = substr($value, 0, 4); $string_results_array["{$array_name}"] = $value; } ?> Link to comment https://forums.phpfreaks.com/topic/130853-get-text-string-between-two-characters/#findComment-679193 Share on other sites More sharing options...
Gulsaes Posted October 31, 2008 Author Share Posted October 31, 2008 awsome, you put me on the right track, all is working nicely now thanks Link to comment https://forums.phpfreaks.com/topic/130853-get-text-string-between-two-characters/#findComment-679196 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.