Espressioni regolari

8nova

Nuovo Utente
1 Ago 2009
1
0
0
Salve a tutti
Appena iscritto vi sottopongo il mio problema
Da un paio di giorni ho una class che non funziona più a causa dei cambiamenti del sito da dove riceve le informazioni.
Il problema è che guardando il codice delle pagine da cui ottenere le info sembra che non ci sia stato nessun cambiamento...insomma dovrebbe ma non funziona
Grazie per l'aiuto

Codice:
<?php

//-----------------------------------------------------------------
//  Begin MySpace Class
//-----------------------------------------------------------------

class MySpace
{
	////////////////////////////////////////////////////////
	// Function:		 getMyspaceProfileVersion
	// Description:	Returns Profile Version
	
	function getMyspaceProfileVersion()
	{
		if(preg_match('/ProfileVersion":1};/', $this->content, $hit))
		{
			return 1;
		}
		elseif(preg_match('/ProfileVersion":3};/', $this->content, $hit))
		{
			return 2;
		}
	}
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceStatus
	// Description:	Returns Users Status, Profile Hidden?
	
	function getMySpaceStatus()
	{
		if(preg_match('/This profile is set to private. This user must add you as a friend to see his\/her profile./', $this->content, $hit))
		{
			return 1;
		}
		elseif(preg_match('/\<span id="ctl00_ctl00_cpMain_cpMain_Unavailable1_ErrorMessageLabel">Invalid Friend ID./', $this->content, $hit))
		{
			return 2;
		}
		else
		{
			return 3;
		}
	}
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceName
	// Description:	Returns Users Name
	
	function getMySpaceName()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/\<span class="nametext">([^"]+)\<br \/>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return FALSE;
			}
		}
		else
		{
			if(preg_match('/\<h2>([^"]+)\<\/h2>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return FALSE;
			}
		}
	}
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceSex
	// Description:	Returns Users Sex
	
	function getMySpaceSex()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/\<title>([^"]+)\<\/title>/', $this->content, $hit))
			{
				$title = explode(" - ", $hit[1]);
				return $title[3];
			}
			else
			{
				return FALSE;
			}
		}
		else
		{
			if(preg_match('/\<span class="gender">([^"]+)<\/span>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return FALSE;
			}
		}
	}
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceAge
	// Description:	Returns Users Age
	
	function getMySpaceAge()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/\<title>([^"]+)\<\/title>/', $this->content, $hit))
			{
				$title = explode(" - ", $hit[1]);
				return $title[2];
			}
			else
			{
				return FALSE;
			}
		}
		else
		{
			if(preg_match('/\<span class="age">([^"]+)<\/span>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return FALSE;
			}
		}
	}
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceFullName
	// Description:	Returns Users Name
	
	function getMySpaceFullName()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/\<span class="text">([^"]+)\<\/span>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return FALSE;
			}
		}
		else
		{
			if(preg_match('/MySpace profile for ([^"]+). Find friends/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return FALSE;
			}
		}
	}
		
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceUserID
	// Description:	Returns Users Headline
	
	function getMySpaceUserID()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/DisplayFriendId":([^"]+),/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return FALSE;
			}
		}
		else
		{
			if(preg_match('/DisplayFriendId":([^"]+),/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return FALSE;
			}		
		}
	}
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceFriends
	// Description:	Returns Users Friends Count
	
	function getMySpaceFriends()
	{	
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/\<span class="redbtext" property="myspace:friendCount">([^"]+)<\/span>&nbsp;/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return "N/A";
			}
		}
		else 
		{
			if(preg_match('/\<span class="count">([^"]+)<\/span> friends.<\/span>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return "N/A";
			}		
		}
	}
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceComments
	// Description:	Returns Users Comments Count
	
	function getMySpaceCommentsCount()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/\<span class="redtext"> ([^"]+) \<\/span>comments&nbsp;/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return "N/A";
			}
		}
		else 
		{
			if(preg_match('/\<span class="count">([^"]+)<\/span> comments<\/span>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return "N/A";
			}		
		}
	}
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceDefaultPic
	// Description:	Returns Users Default Pic URL
	
	function getMySpaceDefaultPic()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/<img border="0" alt="" src="([^"]+)" \/>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return "N/A";
			}
		}
		else 
		{
			if(preg_match('/\<img class="photo " alt="Photo of ([^"]+)" src="([^"]+)" \/>/', $this->content, $hit))
			{
				return $hit[2];
			}
			else
			{
				return "N/A";
			}		
		}
	} 
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceURL
	// Description:	Returns Users Myspace URL
	
	function getMySpaceURL()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/\<title>([^"]+)\<\/title>/', $this->content, $hit))
			{
				$title = explode(" - ", $hit[1]);
				return $title[5];
			}
			else
			{
				return "N/A";
			}
		}
		else
		{
			if(preg_match('/class="url">([^"]+)<\/a><\/span>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return "N/A";
			}
		}
	}
	 
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceLocation
	// Description:	Returns Users Myspace Location
	
	function getMySpaceLocation()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/\<title>([^"]+)\<\/title>/', $this->content, $hit))
			{
				$explode = explode(" - ", $hit[1]);
				return $explode[4];
			}
			else
			{
				return "N/A";
			}
		}
		else
		{
			if(preg_match('/\<span class="locality">([^"]+)<\/span>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return "N/A";
			}		
		}
	}
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceSaying
	// Description:	Returns Users Myspace Saying
	
	function getMySpaceSaying()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/\<meta name="description" content="([^"]+)" \/>/', $this->content, $hit))
			{
				$explode = explode(", ", $hit[1]);
				return $explode[6];
			}
			else
			{
				return "N/A";
			}
		}
		else
		{
			if(preg_match('/\<span class="status">([^"]+)<\/span>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return "N/A";
			}
		}
	}
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceMood
	// Description:	Returns Users Myspace Mood
	
	function getMySpaceMood()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/\<span property="myspace:mood">([^"]+)<\/span>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return "N/A";
			}
		}
		else
		{
			if(preg_match('/\<span class="mood"><strong>Mood:<\/strong> ([^"]+) <img/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return "N/A";
			}
		}
	}
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceLastLogin
	// Description:	Returns Users Myspace Last Login
		
	function getMySpaceLastLogin()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(preg_match('/datatype="xsd:date">([^"]+)<\/span>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return "N/A";
			}
		}
		else
		{
			if(preg_match('/Last Login: ([^"]+)<\/li>/', $this->content, $hit))
			{
				return $hit[1];
			}
			else
			{
				return "N/A";
			}
		}
	}
	
	////////////////////////////////////////////////////////
	// Function:		 getMySpaceComments
	// Description:	Returns Myspace comments
	
	function getMySpaceComments()
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			$tmp1 = explode("<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\" bordercolor=\"FFffff\">", $this->content);
			$tmp2 = explode("</table> </td> </tr>", $tmp1[1]);
			$tmp3 = explode("<tr>", $tmp2[0]);
	
			for($i=1;$i<count($tmp3);$i++)
			{
				$hit[$i]['link'] = $this->strip($tmp3[$i], "<a href=\"", "\">");
				$hit[$i]['name'] = $this->strip($tmp3[$i], $this->strip($tmp3[$i], "<a href=\"", "\">")."\">", "</a>");
				$hit[$i]['date'] = $this->strip($tmp3[$i], "<span class=\"blacktext10\">", "</span>");
				$hit[$i]['comment'] = $this->strip($tmp3[$i], "</span>", "</td>");
			}
	
			return $hit;
		}
		else return "Not yet implimented";
	}
	
	////////////////////////////////////////////////////////
	// Function:		 strip
	// Description:	Strips the fields for result
	
	function strip($str, $start, $end)
	{
		if($this->getMyspaceProfileVersion() == 1)
		{
			if(empty($str))
			{
					return;
			}
			$str_low = strtolower($str);
			$pos_start = strpos($str_low, $start);
			$pos_end = strpos($str_low, $end, ($pos_start + strlen($start)));
			if ( ($pos_start !== false) && ($pos_end !== false) )
			{
					$pos1 = $pos_start + strlen($start);
					$pos2 = $pos_end - $pos1;
					return substr($str, $pos1, $pos2);
			}
		}
		else return "Not yet implimented";
	}
	
	////////////////////////////////////////////////////////
	// Function:		 MySpace
	// Description:	Connects to MySpace
	
	function MySpace($title)
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $title);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		$this->content = curl_exec($ch);
		curl_close($ch);
	}
}  
?>
 

Discussioni simili