User:Crooked Shim

From Second Life Wiki
Revision as of 21:05, 6 May 2010 by Kuraiko Yoshikawa (talk | contribs) (syntax highlighting)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Useful PHP Functions

These may break at any time, depends on if LL changes SL search too much.

Name2Key

<php> function get_key($user_name) { $url = sprintf('http://search.secondlife.com/web/search/?q=%s', urlencode($user_name)); $ch = curl_init(); curl_setopt_array($ch, array(CURLOPT_URL=>$url, CURLOPT_RETURNTRANSFER=>true, CURLOPT_CONNECTTIMEOUT=>5, CURLOPT_USERAGENT=>"Name2Key")); $output = curl_exec($ch); curl_close($ch); $user_name = strtoupper($user_name); preg_match_all('%<a href="http://world\.secondlife\.com/resident/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})">(?:)?(.+?)(?:)?</a>%', $output, $matches, PREG_SET_ORDER); foreach ($matches as $val) { if (strtoupper($val[2]) == $user_name) { return $val[1]; } } return 'not_found'; } </php>

Key2Name

<php> function get_name($user_key) { $url = sprintf('http://world.secondlife.com/resident/%s', urlencode($user_key)); $ch = curl_init(); curl_setopt_array($ch, array(CURLOPT_URL=>$url, CURLOPT_RETURNTRANSFER=>true, CURLOPT_CONNECTTIMEOUT=>5)); $output = curl_exec($ch); curl_close($ch); preg_match('%<title>(.+?)</title>%', $output, $matches); if (!empty($matches[1])) return $matches[1]; else return 'not_found'; } </php>

Key2Birthday

<php> function get_birthday($user_key) { $url = sprintf('http://world.secondlife.com/resident/%s', urlencode($user_key)); $ch = curl_init(); curl_setopt_array($ch, array(CURLOPT_URL=>$url, CURLOPT_RETURNTRANSFER=>true, CURLOPT_CONNECTTIMEOUT=>5, CURLOPT_USERAGENT=>"Key2DOB")); $output = curl_exec($ch); curl_close($ch);

if (strpos($output, 'AccessDenied') !== false) return 'not_found';

if (preg_match('%Resident Since:\s\s(\d+?)-(\d+?)-(\d+?)\s%', $output, $matches)) return array_slice($matches, 1); else return 'not_found'; } </php>