php_b34st Posted August 6, 2008 Share Posted August 6, 2008 I have the following script: <?php //Get the fullpage $fullpage = file_get_contents('http://www.dreamteamfc.com/fantasyfootball/0809/viewplayerlist.aspx?pp=1'); preg_match_all('#<table class="players" cellpadding="0" cellspacing="0" border="0">(.*?)</table>#s', $fullpage, $data); //Strip html tags $playerlist = $data[1][0]; $playerlist = strip_tags($playerlist); //Seperate the data so its useable $result = explode ("\n", $playerlist); //display results foreach ($result as $value) { echo $value.'</br>'; } ?> The script goes to a website and gets the contents of the page i then strip out the section I need and seperate the data. At the moment it outputs like this: Code Name Club Price Points 002 M Almunia Arsenal £5.0m 0 005 L Fabianski Arsenal £2.5m 0 etc... however I would like it to not show code name club price points but instead put the information into an array so that i can add the data into a mysql db using $code $name $club $price $points I have always struggled with arrays so any help would be great thanks Link to comment https://forums.phpfreaks.com/topic/118515-solved-inserting-data-into-arrays/ Share on other sites More sharing options...
php_b34st Posted August 6, 2008 Author Share Posted August 6, 2008 I think I need to insert into an array like this: Array ( [1] => Array ( [code] => 002 [name] => M Almunia [club] => Arsenal [price] => £5.0m [points] => 0 ) [2] => Array ( [code] => 005 [name] => L Fabianski [club] => Arsenal [price] => £2.5m [points] => 0 ) etc I can only get the values into one big array and dont know how to split them up to put into a multi-dimenisional array. I tried to use list() but again couldnt make it multi-dimensional.[/code][/code] Link to comment https://forums.phpfreaks.com/topic/118515-solved-inserting-data-into-arrays/#findComment-610251 Share on other sites More sharing options...
Barand Posted August 6, 2008 Share Posted August 6, 2008 can you post the output from var_export($result); Link to comment https://forums.phpfreaks.com/topic/118515-solved-inserting-data-into-arrays/#findComment-610257 Share on other sites More sharing options...
php_b34st Posted August 6, 2008 Author Share Posted August 6, 2008 sure the output is: array ( 0 => ' ', 1 => ' ', 2 => ' ', 3 => ' ', 4 => ' ', 5 => ' ', 6 => ' ', 7 => ' ', 8 => ' Code ', 9 => ' Name ', 10 => ' Club ', 11 => ' Price ', 12 => ' Points ', 13 => ' ', 14 => ' ', 15 => ' ', 16 => ' ', 17 => ' ', 18 => ' ', 19 => ' 002 ', 20 => ' M Almunia ', 21 => ' Arsenal ', 22 => ' £5.0m ', 23 => ' 0 ', 24 => ' ', 25 => ' ', 26 => ' ', 27 => ' 005 ', 28 => ' L Fabianski ', 29 => ' Arsenal ', 30 => ' £2.5m ', 31 => ' 0 ', 32 => ' ', 33 => ' ', 34 => ' ', 35 => ' 009 ', 36 => ' S Taylor ', 37 => ' Aston Villa ', 38 => ' £2.5m ', 39 => ' 0 ', 40 => ' ', 41 => ' ', 42 => ' ', 43 => ' 013 ', 44 => ' B Friedel ', 45 => ' Blackburn ', 46 => ' £4.0m ', 47 => ' 0 ', 48 => ' ', 49 => ' ', 50 => ' ', 51 => ' 017 ', 52 => ' A Al Habsi ', 53 => ' Bolton ', 54 => ' £1.5m ', 55 => ' 0 ', 56 => ' ', 57 => ' ', 58 => ' ', 59 => ' 020 ', 60 => ' J Jaaskelainen ', 61 => ' Bolton ', 62 => ' £3.0m ', 63 => ' 0 ', 64 => ' ', 65 => ' ', 66 => ' ', 67 => ' 024 ', 68 => ' P Cech ', 69 => ' Chelsea ', 70 => ' £5.5m ', 71 => ' 0 ', 72 => ' ', 73 => ' ', 74 => ' ', 75 => ' 027 ', 76 => ' C Cudicini ', 77 => ' Chelsea ', 78 => ' £2.5m ', 79 => ' 0 ', 80 => ' ', 81 => ' ', 82 => ' ', 83 => ' 031 ', 84 => ' T Howard ', 85 => ' Everton ', 86 => ' £5.0m ', 87 => ' 0 ', 88 => ' ', 89 => ' ', 90 => ' ', 91 => ' 035 ', 92 => ' M Schwarzer ', 93 => ' Fulham ', 94 => ' £2.0m ', 95 => ' 0 ', 96 => ' ', 97 => ' ', 98 => ' ', 99 => ' 039 ', 100 => ' B Myhill ', 101 => ' Hull City ', 102 => ' £1.0m ', 103 => ' 0 ', 104 => ' ', 105 => ' ', 106 => ' ', 107 => ' 043 ', 108 => ' J Reina ', 109 => ' Liverpool ', 110 => ' £5.5m ', 111 => ' 0 ', 112 => ' ', 113 => ' ', 114 => ' ', 115 => ' 047 ', 116 => ' J Hart ', 117 => ' Manchester City ', 118 => ' £4.0m ', 119 => ' 0 ', 120 => ' ', 121 => ' ', 122 => ' ', 123 => ' 051 ', 124 => ' B Foster ', 125 => ' Manchester United ', 126 => ' £3.0m ', 127 => ' 0 ', 128 => ' ', 129 => ' ', 130 => ' ', 131 => ' 054 ', 132 => ' E van der Sar ', 133 => ' Manchester United ', 134 => ' £5.5m ', 135 => ' 0 ', 136 => ' ', 137 => ' ', 138 => ' ', 139 => ' 058 ', 140 => ' B Jones ', 141 => ' Middlesbrough ', 142 => ' £2.0m ', 143 => ' 0 ', 144 => ' ', 145 => ' ', 146 => ' ', 147 => ' 061 ', 148 => ' R Turnbull ', 149 => ' Middlesbrough ', 150 => ' £2.0m ', 151 => ' 0 ', 152 => ' ', 153 => ' ', 154 => ' ', 155 => ' 065 ', 156 => ' S Given ', 157 => ' Newcastle United ', 158 => ' £4.0m ', 159 => ' 0 ', 160 => ' ', 161 => ' ', 162 => ' ', 163 => ' 068 ', 164 => ' S Harper ', 165 => ' Newcastle United ', 166 => ' £2.0m ', 167 => ' 0 ', 168 => ' ', 169 => ' ', 170 => ' ', 171 => ' 072 ', 172 => ' D James ', 173 => ' Portsmouth ', 174 => ' £5.0m ', 175 => ' 0 ', 176 => ' ', 177 => ' ', 178 => ' ', 179 => ' 076 ', 180 => ' S Simonsen ', 181 => ' Stoke ', 182 => ' £1.5m ', 183 => ' 0 ', 184 => ' ', 185 => ' ', 186 => ' ', 187 => ' 080 ', 188 => ' C Gordon ', 189 => ' Sunderland ', 190 => ' £2.5m ', 191 => ' 0 ', 192 => ' ', 193 => ' ', 194 => ' ', 195 => ' 082 ', 196 => ' Gomes ', 197 => ' Tottenham ', 198 => ' £3.0m ', 199 => ' 0 ', 200 => ' ', 201 => ' ', 202 => ' ', 203 => ' 084 ', 204 => ' P Robinson ', 205 => ' Tottenham ', 206 => ' £3.0m ', 207 => ' 0 ', 208 => ' ', 209 => ' ', 210 => ' ', 211 => ' 086 ', 212 => ' S Carson ', 213 => ' West Brom ', 214 => ' £2.5m ', 215 => ' 0 ', 216 => ' ', 217 => ' ', 218 => ' ', 219 => ' 088 ', 220 => ' D Kiely ', 221 => ' West Brom ', 222 => ' £2.0m ', 223 => ' 0 ', 224 => ' ', 225 => ' ', 226 => ' ', 227 => ' 092 ', 228 => ' R Green ', 229 => ' West Ham ', 230 => ' £3.0m ', 231 => ' 0 ', 232 => ' ', 233 => ' ', 234 => ' ', 235 => ' 096 ', 236 => ' C Kirkland ', 237 => ' Wigan ', 238 => ' £2.5m ', 239 => ' 0 ', 240 => ' ', 241 => ' ', 242 => ' ', 243 => ' ', 244 => ' ', ) thanks for looking Link to comment https://forums.phpfreaks.com/topic/118515-solved-inserting-data-into-arrays/#findComment-610258 Share on other sites More sharing options...
moselkady Posted August 7, 2008 Share Posted August 7, 2008 Maybe you can try something like this: <?php // remove blank elements foreach ($result as $a) { if (!ereg("^[[:space:]]+$", $a)) $b[] = $a; } $b = array_chunk($b, 5); print_r($b); ?> Link to comment https://forums.phpfreaks.com/topic/118515-solved-inserting-data-into-arrays/#findComment-610363 Share on other sites More sharing options...
Barand Posted August 7, 2008 Share Posted August 7, 2008 this should give the structure you are looking for <?php $ar = array_slice($result,19); $data = array_chunk($ar, ; // view array echo '<pre>', print_r($data, true), '</pre>'; Link to comment https://forums.phpfreaks.com/topic/118515-solved-inserting-data-into-arrays/#findComment-611021 Share on other sites More sharing options...
php_b34st Posted August 8, 2008 Author Share Posted August 8, 2008 Thanks thats exactly what I was trying to do. Link to comment https://forums.phpfreaks.com/topic/118515-solved-inserting-data-into-arrays/#findComment-611526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.