Difference between revisions of "User:Crooked Shim"
Crooked Shim (talk | contribs) |
m (syntax highlighting) |
||
(One intermediate revision by one other user not shown) | |||
Line 8: | Line 8: | ||
====Name2Key==== | ====Name2Key==== | ||
< | <php> | ||
function get_key($user_name) | function get_key($user_name) | ||
{ | { | ||
Line 27: | Line 27: | ||
return 'not_found'; | return 'not_found'; | ||
} | } | ||
</ | </php> | ||
====Key2Name==== | ====Key2Name==== | ||
< | <php> | ||
function get_name($user_key) | function get_name($user_key) | ||
{ | { | ||
Line 42: | Line 42: | ||
else return 'not_found'; | else return 'not_found'; | ||
} | } | ||
</ | </php> | ||
====Key2Birthday==== | ====Key2Birthday==== | ||
< | <php> | ||
function get_birthday($user_key) | function get_birthday($user_key) | ||
{ | { | ||
$url = sprintf('http://world.secondlife.com/resident/%s', urlencode($user_key)); | $url = sprintf('http://world.secondlife.com/resident/%s', urlencode($user_key)); | ||
$ch = curl_init(); | $ch = curl_init(); | ||
curl_setopt_array($ch, array(CURLOPT_URL=>$url, CURLOPT_RETURNTRANSFER=>true, CURLOPT_CONNECTTIMEOUT=>5, CURLOPT_USERAGENT=>" | curl_setopt_array($ch, array(CURLOPT_URL=>$url, CURLOPT_RETURNTRANSFER=>true, CURLOPT_CONNECTTIMEOUT=>5, CURLOPT_USERAGENT=>"Key2DOB")); | ||
$output = curl_exec($ch); | $output = curl_exec($ch); | ||
curl_close($ch); | curl_close($ch); | ||
Line 59: | Line 59: | ||
else return 'not_found'; | else return 'not_found'; | ||
} | } | ||
</ | </php> | ||
|} | |} |
Latest revision as of 21:05, 6 May 2010
Useful PHP FunctionsThese 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> |