Skip to content

Instantly share code, notes, and snippets.

@tuki0918
Last active August 29, 2015 14:10
Show Gist options
  • Save tuki0918/bd5f3173cb7a7c758b2e to your computer and use it in GitHub Desktop.
Save tuki0918/bd5f3173cb7a7c758b2e to your computer and use it in GitHub Desktop.
search for twitter user_id | reference: http://stabucky.com/wp/archives/2188
<?php
$a = array(0,1,2,3,4,5,6,7,8,9);
$b = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
$c = array('_');
$x = array_merge($a,$b,$c);
function userId($arr, $length = 4){
$max = count($arr);
if ($max < $length) {
return;
} elseif ($length == 1) {
for ($i=0; $i<$max; $i++) {
$keys[$i] = array($arr[$i]);
}
} elseif ($length > 1) {
$j = 0;
for ($i=0; $i<$max-$length+1; $i++) {
$ts = userId(array_slice($arr, $i+1), $length-1);
foreach ($ts as $t) {
array_unshift($t, $arr[$i]);
$keys[$j] = $t;
$j++;
}
}
}
return $keys;
}
$keys = userId($x, 4);
foreach ($keys as $key) {
$id = implode($key);
echo "{$id}\n";
}
<?php
$a = array(0,1,2,3,4,5,6,7,8,9);
$b = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
$c = array('_');
$x = array_merge($a,$b,$c);
date_default_timezone_set('Asia/Tokyo');
mb_language('Japanese');
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
define('PATH', dirname(__FILE__).'/');
define('FILE_NAME', PATH . 'file/userlist.txt');
define('TW_USER_BASEURL', 'https://twitter.com/');
function userId($arr, $length = 4){
$max = count($arr);
if ($max < $length) {
return;
} elseif ($length == 1) {
for ($i=0; $i<$max; $i++) {
$keys[$i] = array($arr[$i]);
}
} elseif ($length > 1) {
$j = 0;
for ($i=0; $i<$max-$length+1; $i++) {
$ts = userId(array_slice($arr, $i+1), $length-1);
foreach ($ts as $t) {
array_unshift($t, $arr[$i]);
$keys[$j] = $t;
$j++;
}
}
}
return $keys;
}
$userlist = file_get_contents(FILE_NAME);
$fp = fopen(FILE_NAME, 'r+');
$keys = userId($x, 4);
foreach ($keys as $key) {
$id = implode($key);
$url = TW_USER_BASEURL.$id;
$pos = strpos($userlist, $url);
if ($pos === false) {
$html = @file_get_contents($url);
if (empty($html)) {
$fields = array($url, 'no');
fputcsv($fp, $fields);
}
}
sleep(1);
}
fclose($fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment