Modernvox Posted November 1, 2009 Share Posted November 1, 2009 Hello brothers I have been struggling with arrays for some time simply because of there output method(s) If i have many links and i want to open them one by one I understand i need to either echo or print_r match[0] I now understand that the [..] holds all the matches. But, if there are 100 links/matches within the [array] how do I open say the fourth link from a row of links? Do i just say echo or print_r match[4]? Do i need to close a link before I can open another? Hey, seriously you guys have been great to me and I am truly amazed at the respect in here. Thanks brothers! Mike Quote Link to comment https://forums.phpfreaks.com/topic/179880-shed-some-light-on-print_r-an-array0/ Share on other sites More sharing options...
Daniel0 Posted November 1, 2009 Share Posted November 1, 2009 If you need to access the fourth element in an array called $array you'll do like this: $array[3] Note that many things in programming and computer science are 0 indexed whereas English generally is 1 indexed. Quote Link to comment https://forums.phpfreaks.com/topic/179880-shed-some-light-on-print_r-an-array0/#findComment-948944 Share on other sites More sharing options...
Modernvox Posted November 2, 2009 Author Share Posted November 2, 2009 Thank You Dan. So if i want to open a link from a list of links I simply call the fopen function to open the link? For example let's say i open the site www.you.com <?php function curlURL($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2'); $output = curl_exec($curl); return $output; } $curlResults = curlURL("http://you.com"); //Now we want to find and open a link from a pattern: $pattern = '#<a href="(/[a-z]{3}/\d{10}\.html)">#'; //example preg_match_all( $pattern, $curlResults, $matches); //Now we have a list of active links matching our pattern // So we want to open them one a at a time //Let's say the links are as follows: http://www.you.com/cars.html http://www.you.com/trucks.html http://www.you.com/gokarts.html http://www.you.com/boats.html What would the code look like for this? Quote Link to comment https://forums.phpfreaks.com/topic/179880-shed-some-light-on-print_r-an-array0/#findComment-948961 Share on other sites More sharing options...
Daniel0 Posted November 2, 2009 Share Posted November 2, 2009 Something like foreach ($matches[1] as $link) { // do stuff } Quote Link to comment https://forums.phpfreaks.com/topic/179880-shed-some-light-on-print_r-an-array0/#findComment-949193 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.