elmbrent Posted June 6, 2012 Share Posted June 6, 2012 Hi Guys, Im very new to PHP as i've been using joomla as a cms for just about everything for 8 years up until now.... :'( I've written this script. <?php //new $url = "http://full-time.thefa.com/Index.do?divisionseason=3535709"; preg_match_all('#<table[^>]+>[\w\W]*?</table>#i', file_get_contents($url), $match); var_dump($match); echo $match[1]; ?> As you can see it pulls in the data via preg_match_all but when i select the array with $match[1] it shows Notice: Undefined offset: 1 in C:\wamp\www\teamsolent.com\PHP\index.php on line 20 This makes no sense to me as it clearly shows all the arrays above it and its saying they don't exist? Kindest Regards Brent Quote Link to comment https://forums.phpfreaks.com/topic/263761-really-simple-error-help/ Share on other sites More sharing options...
elmbrent Posted June 6, 2012 Author Share Posted June 6, 2012 Any ideas anyone, i been stuck on this all day and I cant find anyone that can help me. Quote Link to comment https://forums.phpfreaks.com/topic/263761-really-simple-error-help/#findComment-1351644 Share on other sites More sharing options...
Jessica Posted June 6, 2012 Share Posted June 6, 2012 It means there is nothing at the key of 1 in $match. What was the result of your var dump? I find print_r a bit easier to read than var_dump, so if you are confused by the output try print_r. (within <pre> tags) Quote Link to comment https://forums.phpfreaks.com/topic/263761-really-simple-error-help/#findComment-1351647 Share on other sites More sharing options...
elmbrent Posted June 6, 2012 Author Share Posted June 6, 2012 array(1) { [0]=> array(5) { [0]=> string(10084) " POS P W D L F A GD PTS 1 Verwood Town 34 25 5 4 91 38 53 80 2 AFC Portchester 34 24 4 6 114 52 62 76 3 Team Solent 34 19 7 8 75 52 23 64 4 East Cowes Victoria 34 19 6 9 82 46 36 63 5 Brockenhurst 34 18 9 7 72 41 31 63 6 Cowes Sports 34 15 5 14 62 45 17 50 7 Fleet Spurs 34 14 7 13 45 46 -1 49 8 Whitchurch United 34 13 8 13 50 45 5 47 9 Ringwood Town 34 13 7 14 62 59 3 46 10 Andover New Street 34 13 10 11 53 56 -3 46 * 11 Pewsey Vale 34 12 8 14 51 61 -10 44 12 Petersfield Town 34 12 3 19 67 74 -7 39 13 United Services Portsmouth 34 11 6 17 59 69 -10 39 14 Amesbury Town 34 9 7 18 55 93 -38 34 15 Stockbridge 34 7 12 15 34 63 -29 33 16 Warminster Town 34 8 8 18 56 83 -27 32 17 Tadley Calleva 34 8 4 22 39 82 -43 28 18 Hythe & Dibden 34 6 4 24 47 109 -62 22 Table detail * adjustment made " [1]=> string(11606) " DATE HOME RESULT AWAY SWLC 07/05/12 Brockenhurst 1 - 3 Christchurch SWL1 05/05/12 East Cowes Victoria 0 - 2 Warminster Town SWL1 02/05/12 Brockenhurst 3 - 1 United Services Portsmouth SWL1 01/05/12 Fleet Spurs 2 - 0 Team Solent SWL1 28/04/12 AFC Portchester H - W Andover New Street SWL1 28/04/12 Amesbury Town 4 - 1 Whitchurch United SWL1 28/04/12 Cowes Sports 0 - 3 Pewsey Vale SWL1 28/04/12 Hythe & Dibden 5 - 2 Ringwood Town SWL1 28/04/12 Petersfield Town 2 - 4 Verwood Town SWL1 28/04/12 Stockbridge 2 - 1 Tadley Calleva SWL1 21/04/12 Cowes Sports 2 - 1 Whitchurch United SWL1 21/04/12 Hythe & Dibden 2 - 6 Brockenhurst SWL1 21/04/12 Petersfield Town 1 - 2 Warminster Town SWL1 21/04/12 Pewsey Vale 1 - 1 Andover New Street SWL1 21/04/12 Ringwood Town 0 - 1 Fleet Spurs SWL1 21/04/12 Tadley Calleva 3 - 2 Amesbury Town SWL1 21/04/12 Team Solent 1 - 4 AFC Portchester SWL1 14/04/12 AFC Portchester 2 - 0 Fleet Spurs See all results " [2]=> string(468) " DATE HOME AWAY See all fixtures " [3]=> string(484) " DATE HOME AWAY STATUS See all fixtures " [4]=> string(189) " " } } That what happens when i Var Dumb, so it has arrays but I cant echo them out, im so very confused. Quote Link to comment https://forums.phpfreaks.com/topic/263761-really-simple-error-help/#findComment-1351652 Share on other sites More sharing options...
Jessica Posted June 6, 2012 Share Posted June 6, 2012 try print_r instead then as it will show you what's in the arrays. Also, put this in code tags. You know the first key in an array will be 0, not 1, right? See how it's [0] as the first and not [1]? So when you try to access $match[1] I think you mean to do [0]. Quote Link to comment https://forums.phpfreaks.com/topic/263761-really-simple-error-help/#findComment-1351654 Share on other sites More sharing options...
elmbrent Posted June 6, 2012 Author Share Posted June 6, 2012 When I print_r I get the same as before, array ( [0] => Array ( [0] => POS P W D L F A GD PTS 1 Verwood Town 34 25 5 4 91 38 53 80 2 AFC Portchester 34 24 4 6 114 52 62 76 3 Team Solent 34 19 7 8 75 52 23 64 4 East Cowes Victoria 34 19 6 9 82 46 36 63 5 Brockenhurst 34 18 9 7 72 41 31 63 6 Cowes Sports 34 15 5 14 62 45 17 50 7 Fleet Spurs 34 14 7 13 45 46 -1 49 8 Whitchurch United 34 13 8 13 50 45 5 47 9 Ringwood Town 34 13 7 14 62 59 3 46 10 Andover New Street 34 13 10 11 53 56 -3 46 * 11 Pewsey Vale 34 12 8 14 51 61 -10 44 12 Petersfield Town 34 12 3 19 67 74 -7 39 13 United Services Portsmouth 34 11 6 17 59 69 -10 39 14 Amesbury Town 34 9 7 18 55 93 -38 34 15 Stockbridge 34 7 12 15 34 63 -29 33 16 Warminster Town 34 8 8 18 56 83 -27 32 17 Tadley Calleva 34 8 4 22 39 82 -43 28 18 Hythe & Dibden 34 6 4 24 47 109 -62 22 Table detail * adjustment made [1] => DATE HOME RESULT AWAY SWLC 07/05/12 Brockenhurst 1 - 3 Christchurch SWL1 05/05/12 East Cowes Victoria 0 - 2 Warminster Town SWL1 02/05/12 Brockenhurst 3 - 1 United Services Portsmouth SWL1 01/05/12 Fleet Spurs 2 - 0 Team Solent SWL1 28/04/12 AFC Portchester H - W Andover New Street SWL1 28/04/12 Amesbury Town 4 - 1 Whitchurch United SWL1 28/04/12 Cowes Sports 0 - 3 Pewsey Vale SWL1 28/04/12 Hythe & Dibden 5 - 2 Ringwood Town SWL1 28/04/12 Petersfield Town 2 - 4 Verwood Town SWL1 28/04/12 Stockbridge 2 - 1 Tadley Calleva SWL1 21/04/12 Cowes Sports 2 - 1 Whitchurch United SWL1 21/04/12 Hythe & Dibden 2 - 6 Brockenhurst SWL1 21/04/12 Petersfield Town 1 - 2 Warminster Town SWL1 21/04/12 Pewsey Vale 1 - 1 Andover New Street SWL1 21/04/12 Ringwood Town 0 - 1 Fleet Spurs SWL1 21/04/12 Tadley Calleva 3 - 2 Amesbury Town SWL1 21/04/12 Team Solent 1 - 4 AFC Portchester SWL1 14/04/12 AFC Portchester 2 - 0 Fleet Spurs See all results [2] => DATE HOME AWAY See all fixtures [3] => DATE HOME AWAY STATUS See all fixtures [4] => ) ) Array I know that 0 will post the 0 array but I want the [1] which is bellow, but evan [0] has same error. I cant get my head round why i can see the array but i can echo it? Thanks [1] => DATE HOME RESULT AWAY SWLC 07/05/12 Brockenhurst 1 - 3 Christchurch SWL1 05/05/12 East Cowes Victoria 0 - 2 Warminster Town SWL1 02/05/12 Brockenhurst 3 - 1 United Services Portsmouth SWL1 01/05/12 Fleet Spurs 2 - 0 Team Solent SWL1 28/04/12 AFC Portchester H - W Andover New Street SWL1 28/04/12 Amesbury Town 4 - 1 Whitchurch United SWL1 28/04/12 Cowes Sports 0 - 3 Pewsey Vale SWL1 28/04/12 Hythe & Dibden 5 - 2 Ringwood Town SWL1 28/04/12 Petersfield Town 2 - 4 Verwood Town SWL1 28/04/12 Stockbridge 2 - 1 Tadley Calleva SWL1 21/04/12 Cowes Sports 2 - 1 Whitchurch United SWL1 21/04/12 Hythe & Dibden 2 - 6 Brockenhurst SWL1 21/04/12 Petersfield Town 1 - 2 Warminster Town SWL1 21/04/12 Pewsey Vale 1 - 1 Andover New Street SWL1 21/04/12 Ringwood Town 0 - 1 Fleet Spurs SWL1 21/04/12 Tadley Calleva 3 - 2 Amesbury Town SWL1 21/04/12 Team Solent 1 - 4 AFC Portchester SWL1 14/04/12 AFC Portchester 2 - 0 Fleet Spurs See all results Quote Link to comment https://forums.phpfreaks.com/topic/263761-really-simple-error-help/#findComment-1351661 Share on other sites More sharing options...
elmbrent Posted June 7, 2012 Author Share Posted June 7, 2012 any ideas anyone? I'm really stuck and i know theres some genius out there that can solve this in one word Quote Link to comment https://forums.phpfreaks.com/topic/263761-really-simple-error-help/#findComment-1351821 Share on other sites More sharing options...
ejay Posted June 7, 2012 Share Posted June 7, 2012 you need to do echo $match[0][1]; instead of echo $match[1]; Quote Link to comment https://forums.phpfreaks.com/topic/263761-really-simple-error-help/#findComment-1351825 Share on other sites More sharing options...
elmbrent Posted June 7, 2012 Author Share Posted June 7, 2012 Thankyou so much!, can i ask why that worked? Quote Link to comment https://forums.phpfreaks.com/topic/263761-really-simple-error-help/#findComment-1351838 Share on other sites More sharing options...
ejay Posted June 7, 2012 Share Posted June 7, 2012 you were misreading the array structure. The first line in var_dump output in reply # 3 is "array(1) {" which indicates that the outer array has only one element in it, so you can't do $matches[1] Please mark solved if it is solved Quote Link to comment https://forums.phpfreaks.com/topic/263761-really-simple-error-help/#findComment-1351840 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.