Jump to content

how to combine arrays


quickstopman

Recommended Posts

hi guys i have a script that gets info from myspace

but when i get the info its in seperate arrays

so theres a seperate array for images

seperate array for id's

and a seperate array for the name

how exactly would i be able to combine them all

and the loop them so it prints out a list of names which are all links to profiles.

here is the code:

<?php
class myspace 
{ 
   var $myID; 
   var $token; 
   var $pageSource; 
   var $ch; 

   var $m_friends = array("id" => array(), "name" => array(), "img_url" => array()); 
   var $m_inboxMessageList = array(array(), array(), array(), array(), array(), array()); 
   var $m_searchResult = array(); 

   function myspace() { 
      $this->ch = curl_init(); 
      $randnum = rand(1,9999999); 
      curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->dir_path."/tmp/cookiejar-$randnum"); 
      curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->dir_path."/tmp/cookiejar-$randnum"); 
      curl_setopt($this->ch, CURLOPT_USERAGENT, 
         "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) ". 
         "Gecko/20071204 Firefox/2.0.0.3"); 
      curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1); 
      curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($this->ch, CURLOPT_POST, 0); 
   } 

   function newLocation($loc) { 
      curl_setopt($this->ch, CURLOPT_URL, $loc.$this->token); 
      curl_setopt($this->ch, CURLOPT_POST, 0); 
      $this->pageSource = curl_exec($this->ch); 

      // The token changes with each page, but I don't think it's necessary to 
      // update it each time. Also, different pages either put a quote at the end of the 
      // token, or they put " at the end (annoyyyyyying...) 
   } 

   function login($email, $password) { 
      curl_setopt($this->ch, CURLOPT_URL, "http://www.myspace.com"); 
      $page = curl_exec($this->ch); 
       
      preg_match("/;MyToken=([^\"]+)\"/", $page, $token); 
      $token = $token[1]; 
       
      # Do login 
      curl_setopt($this->ch, CURLOPT_URL, 
         "http://login.myspace.com/index.cfm?fuseaction=login.process&MyToken={$token}"); 
      curl_setopt($this->ch, CURLOPT_REFERER, "http://www.myspace.com"); 
      curl_setopt($this->ch, CURLOPT_HTTPHEADER, 
         Array("Content-Type: application/x-www-form-urlencoded")); 
      curl_setopt($this->ch, CURLOPT_POST, 1); 
      $postfields = "email=" . urlencode($email); 
      $postfields .= "&password=" . urlencode($password); 
      $postfields .= "&ctl00%24Main%24SplashDisplay%24login%24loginbutton.x=" . 
            "38&ctl00%24Main%24SplashDisplay%24login%24loginbutton.y=15"; 
      curl_setopt($this->ch, CURLOPT_POSTFIELDS,$postfields); 
      $this->pageSource = curl_exec($this->ch); 
      $old_token=$token; 
      $token=NULL; 
      preg_match("/fuseaction=user&Mytoken=(.*)\"/", $this->pageSource, $token); 
      $this->token = "&MyToken={$token[1]}"; 
      $redirpage="http://home.myspace.com/index.cfm?fuseaction=user{$this->token}"; 
       
      # Do the redirect 
      curl_setopt($this->ch, CURLOPT_REFERER, 
         "http://login.myspace.com/index.cfm?fuseaction=login.process{$this->$token}"); 
      curl_setopt($this->ch, CURLOPT_URL,$redirpage); 
      curl_setopt($this->ch, CURLOPT_POST, 0); 

      $page = curl_exec($this->ch); 
       
      # Check login error 
      if(strpos($page,"You Must Be Logged-In to do That!") !== false) 
         return false; 

      # Logged in successfully 
      $this->newLocation("http://home.myspace.com/index.cfm?fuseaction=user"); 
      //echo $this->pageSource; 

      # Find the user's ID (becomes useful later) 
      preg_match("/\"UserId\".*),\"DisplayFriendId\"/", $this->pageSource, $id); 
      $this->myID = $id[1]; 
      return true; 
   } 
    
   function grabFriends() { 
      $ms_f_url = "http://collect.myspace.com/index.cfm?". 
            "fuseaction=user.editfriends&friendID={$this->myID}"; 
      $this->newLocation($ms_f_url); 
    
      # First get the number of friend pages the user has, so we can loop through all of 
      # them and grab all friends 
      preg_match_all("|<a href=\"javascript:NextPage\('(.*)'\)\">(.*)</a>|", 
            $this->pageSource, $pages); 
      $num_pages = 1; 
      if($pages[2][0]) $num_pages = $pages[2][count($pages[2])-2]; 

      for($i = 0; $i < $num_pages; $i++) { 
         $ms_f_url = "http://collect.myspace.com/index.cfm?". 
               "fuseaction=user.editfriends&friendID={$this->myID}&page={$i}"; 
         $this->newLocation($ms_f_url); 
    
         # We're at the "Edit Friends" page, now grab each friend's ID ([1])  and Name ([2]) 
         preg_match_all("|&friendID=(.*)\">(.*)</b></a></td>|", 
                  $this->pageSource, $IDName); 

         # Grab each friend's image URL ([1]) 
         preg_match_all("|<img src=\"(.*)\" width=\"75\"|", $this->pageSource, $images); 
          
         # Set the friends var 
         $this->m_friends["id"] = array_merge($this->m_friends["id"], $IDName[1]); 
         $this->m_friends["name"] = array_merge($this->m_friends["name"], $IDName[2]); 
         $this->m_friends["img_url"] = array_merge($this->m_friends["img_url"], $images[1]); 
      } 
   } 


   function getInboxMessageList() { 
      $ms_f_url = "http://messaging.myspace.com/index.cfm?fuseaction=mail.inbox"; 
      $this->newLocation($ms_f_url); 

      # HTML outside of the message listing can confuse the preg_match_all procs below 
      # So only use the message-listing table 
      $beg_pos = strpos($this->pageSource, 
            "<table id=\"messages\" class=\"cols\" width=\"100%\">"); 
      $end_pos = strpos($this->pageSource, "</table>", $beg_pos); 
      $this->pageSource = substr($this->pageSource, $beg_pos, $end_pos - $beg_pos); 

      preg_match_all("|<td class=\"messageListCell\" ". 
            "style=\"word-wrap:break-word;\">\r\n(.*)</td>|", 
            $this->pageSource, $dates); 

      foreach($dates[1] as $key => $value) 
         $dates[1][$key] = trim(str_replace("<br>", "", $value)); 

      preg_match_all("|&friendid=(.*)\">(.*)</a>|", $this->pageSource, $senders); 
    
      # I'm not really sure why but the above preg_match doesn't return an array of just sender 
      # IDs and names, so we have to unset or delete every even result. To see what I mean, try 
      # print_r($senders) before this operation 
      $senders_count = count($senders[2]); 
      for($i = 0; $i < $senders_count; $i+=2) { 
         unset($senders[1][$i]); unset($senders[2][$i]); 
      } 

      preg_match_all("|<span id=\"(.*)\">(.*)</span>|", $this->pageSource, $status); 
      unset($status[2][0]); 

      preg_match_all("|<a id=\"(.*)\" ". 
            "class=\"subjectHyperlink\" href=\"(.*)\">(.*)</a></td>|", 
            $this->pageSource, $links_subjects); 

      # Replace all the '&' occurrences with '&' 
      foreach($links_subjects[2] as $key => $value) 
         $links_subjects[2][$key] = str_replace("&", "&", $value); 

      # In order: date&time, sender ID, sender name, msg status, full URL to msg, msg subject 
      $this->m_inboxMessageList[0] = array_merge($this->m_inboxMessageList[0], $dates[1]); 
      $this->m_inboxMessageList[1] = array_merge($this->m_inboxMessageList[1], $senders[1]); 
      $this->m_inboxMessageList[2] = array_merge($this->m_inboxMessageList[2], $senders[2]); 
      $this->m_inboxMessageList[3] = array_merge($this->m_inboxMessageList[3], $status[2]); 
      $this->m_inboxMessageList[4] = array_merge($this->m_inboxMessageList[4], $links_subjects[2]); 
      $this->m_inboxMessageList[5] = array_merge($this->m_inboxMessageList[5], $links_subjects[3]); 
   } 

   function searchByEmail($email) { 
      $ms_f_url = "http://searchresults.myspace.com/index.cfm?fuseaction=find.search". 
         "&searchType=network&interesttype=&country=&searchBy=Email". 
         "&f_first_name=".urlencode($email)."&Submit=Find&SearchBoxID=FindAFriend"; 
      $this->newLocation($ms_f_url); 

      $this->m_searchResult[] = $email; 

      if(strstr($this->pageSource, "<table class=\"findpaging\"") == false) 
         return false; 

      preg_match("|<td class=\"pic\"><a href=\"(.*)\"><img src=\"(.*)\" /><br />(.*)</a>|", 
         $this->pageSource, $searchResult); 

      # In order: E-Mail, User ID, Image URL, Name (E-Mail was added above) 
      $this->m_searchResult[] = substr($searchResult[1], strrpos($searchResult[1], "=")+1); 
      $this->m_searchResult[] = $searchResult[2]; 
      $this->m_searchResult[] = $searchResult[3]; 
      return true; 
   } 
} 
?>

Link to comment
https://forums.phpfreaks.com/topic/82557-how-to-combine-arrays/
Share on other sites

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.