looks like someone has already made it.
http://www.mircscripts.org/showdoc.php?type=code&id=4491
its a great looking script btw, nice compact use of COM too.
i think it has many practical uses. many site offer a JSON web service
even google offers a multitude:
youtube
dictionary
web search
translate
to name a few
And as for parsing, you could use a COM call to MSScriptControl.ScriptControl
but anyway, it seems im alone in thinking there is a practical use for this in mirc. ah well
i know youtube is changing its html all the time, and parsing it is becoming harder.
One alternative to get youtube info cleanly, from a more stable source is googles own youtube api
http://code.google.com/apis/youtube/2.0/developers_guide_protocol.html
but the real challenge lies in someone making their own json_decode alias. but hell, you could just regex match the json string instead.
heres an example url for one result. and the query = the youtube url
http://gdata.youtube.com/feeds/api/videos?q=http://www.youtube.com/watch?v=Nrm8-vnSEfc&start-index=1&max-results=1&v=2&alt=json
ps: json services are very fast indeed
have phun.
i added the $fileType array
function dir2array($targetDir, &$fileType){
$filesArray = array();
if ($handle = opendir($targetDir)){
while (false !== ($file = readdir($handle))){
if(in_array(end(explode(".", $file)), $fileType)){
$filesArray[] = $file;
}
}
closedir($handle);
}
if (count($filesArray) > 0) {
return $filesArray;
} else {
return FALSE;
}
}
// Usage Examples:
$arrayName = dir2array("path/to/directory", $arr = array("jpg", "png", "gif"));
$randfile = $arrayName[array_rand($arrayName)];
if(FALSE !== ($arrayName = dir2array("path/to/directory", $arr = array("jpg", "png", "gif")))){ $randfile = $arrayName[array_rand($arrayName)]; }
this should meet what's required
and can be quickly edited to handle a $fileType array
// Put all files of a directory of A selected filetype into an array.
function dir2array($targetDir, $fileType){
$filesArray = array();
if ($handle = opendir($targetDir)){
while (false !== ($file = readdir($handle))){
if(end(explode(".", $file)) == $fileType){
$filesArray[] = $file;
}
}
closedir($handle);
}
if (count($filesArray) > 0) {
return $filesArray;
} else {
return FALSE;
}
}
// Usage examples:
$arrayName = dir2array("path/to/directory", "jpg");
$randfile = $arrayName[array_rand($arrayName)];
if(FALSE !== ($arrayName = dir2array("path/to/directory", "png"))){ $randfile = $arrayName[array_rand($arrayName)]; }
of course, it's the main other language i use, even though i hardly do it these days.
I used to code mIRC a long time ago. but, i really don't see the point in applying all that time and effort into a language thats of no use outside of mIRCLAND. Thats just my opinion though. Not trying to get on anyones tits. :P
by closing the socket. try using socket_ functions in php. example here http://www.hawkee.com/snippet/6076/
by the way killwithme, if you launch the script with a .bat file it uses cmd.exe as the bot window.