Jump to content

Shed Some Light on Print_r an Array[0]


Modernvox

Recommended Posts

Hello brothers :D

 

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

Link to comment
https://forums.phpfreaks.com/topic/179880-shed-some-light-on-print_r-an-array0/
Share on other sites

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.