Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define ('TMPS','tmp_files');
- echo '<br>';
- echo $_SERVER["SCRIPT_NAME"].'<br/>';
- echo $_SERVER["SCRIPT_FILENAME"].'<br/>';
- echo $_SERVER["PHP_SELF"].'<br/>';
- echo $_SERVER["REQUEST_URI"].'<br/>';
- echo $_SERVER["DOCUMENT_ROOT"].'<br/>';
- echo $_SERVER["QUERY_STRING"].'<br/>';
- $testarr = preg_split ('/\//i', $_SERVER["SCRIPT_FILENAME"]);
- //$testarr = explode ('/',$_SERVER["SCRIPT_FILENAME"]);
- echo "<ul>";
- foreach ($testarr as $key=>$el) {
- echo "<li>{$el}</li>";
- }
- echo "</ul>";
- $turl = 'http://google.ru/search';
- $zz = array('q'=>'test', 'oq'=>'ัะตัั', 'num'=>100, 'hl'=>'ru', 'newwindow'=>1);
- $qs = http_build_query($zz);
- echo $qs.'<br/>';
- if (!file_exists(TMPS))
- mkdir(TMPS);
- $fname=TMPS.'/'.str_replace(array('/',':'),array('_',''), $turl).'.tmpz';
- if (file_exists($fname)) {
- echo "getting from file<br/>";
- $fh = fopen ($fname,'r');
- $s = fread($fh, filesize($fname));
- fclose($fh);
- echo '<pre>'.htmlentities($s).'</pre>';
- }
- else {
- echo "getting from url<br/>";
- $s = file_get_contents($turl.'?'.$qs);
- echo '<pre>'.htmlentities($s).'</pre>';
- $fh = fopen($fname,'w');
- fwrite($fh,$s, strlen($s));
- fclose($fh);
- }
- preg_match('/<[^>]*div[^>]*id=["\']search["\'][^>]*>/ims',$s, $matches, PREG_OFFSET_CAPTURE);
- // $s = substr ($s, $matches[1]);
- preg_match_all(
- '/<\s*h3\s*class=["\']r["\']\s*>.*?<[^>]*a[^>]*href="(.*?)"[^>]*>(.*?)<\/a>/ims',
- $s, $matches);
- for ($i=0; $i<count($matches[1]); $i++) {
- $matches[1][$i]=substr(strstr($matches[1][$i],'url?q='),strlen('url?q='));
- $matches[2][$i]=strip_tags($matches[2][$i]);
- }
- unset($matches[0]);
- //echo '<pre>'.print_r($matches[1], true).'</pre>';
- function parsearrurls($el) {
- $f = parse_url($el);
- $z = array();
- $z[0]=$el;
- @$z[1]=$f['scheme'];
- @$z[2]=$f['host'];
- @$z[3]=$f['path'];
- @$z[4]=$f['query'];
- @$z[5]=$f['fragment'];
- return $z;
- }
- $arrparts = array_map('parsearrurls', $matches[1]);
- $func = create_function('$el','return $el[2];');
- $arrhosts = array_map($func, $arrparts);
- foreach ($arrhosts as &$arrhost) {
- //echo $arrhost.'<br/>';
- $arrhost=substr(strstr($arrhost,'www.'),strlen('www.'));
- }
- $arrhosts = array_unique($arrhosts,SORT_STRING);
- echo '<pre>'.print_r($arrhosts, true).'</pre>';
- //----------------------------------------------------------------------------------
- ?>
- <?php
- //-----------------------------
- function fsort($a, $b) {
- if (is_dir($a)) {
- if (is_dir($b)) {
- return strcasecmp($a,$b);
- }
- else return -1;
- } else {
- if (is_dir($b))
- return 1;
- else
- return strcasecmp($a,$b);
- }
- }
- //-----------------------------
- function rpart($a) {
- if (is_dir($a))
- return '<a href="#" onclick="opclo(this);return false;"><b>'.
- substr(strrchr($a,'/'),1).'</b></a>';
- else
- return substr(strrchr($a,'/'),1);
- }
- //-----------------------------
- function printarel ($el, $key) {
- echo $el.'<br>';
- if (is_dir($key)) {
- $f = array();
- echo '<div class="dirdiv">';
- zreaddir($key, $f);
- echo '</div>';
- }
- }
- //-----------------------------
- function zreaddir($dirstr, &$inarr) {
- $d = opendir($dirstr);
- while ($f=readdir($d)) {
- if (($f=='.') || ($f=='..')) continue;
- $inarr[$dirstr.'/'.$f]=$dirstr.'/'.$f;
- }
- uasort($inarr,'fsort');
- $inarr = array_map('rpart',$inarr);
- echo '<div style="margin-left:40px;">';
- array_walk($inarr,'printarel');
- echo '</div>';
- }
- $uuu = <<<INF
- <script type="text/javascript">
- function opclo(el) {
- z = el.nextSibling;
- while (z) {
- if (z.className=='dirdiv') {
- z.style.display=(!z.style.display)?'block':'';
- break;
- }
- z=z.nextSibling;
- }
- }
- </script>
- <style type="text/css">
- a {
- color:black;
- text-decoration:none;
- }
- .dirdiv {
- display:none;
- }
- </style>
- INF;
- echo $uuu;
- $basearr = array();
- zreaddir('..', $basearr);
- //-------------------------------------------------------------------------------
- ?>
- <?php
- $fh = fopen ('urls.txt','r');
- $s= fread ($fh, filesize('urls.txt'));
- $arr = explode('|', $s);
- //-------------------------------------
- function z_el($el) {
- echo $el."<br/>";
- }
- //-------------------------------------
- function filt($el) {
- return $el!='';
- }
- //-------------------------------------
- function getdom($el) {
- return strrchr($el,'.');
- }
- //-------------------------------------
- function combarrs($el1, $el4) {
- $f= array();
- $f['domain']=$el4;
- $f['addr']=$el1;
- return $f;
- }
- //-------------------------------------
- function zsort($a, $b) {
- $uu = strcasecmp($a['domain'], $b['domain']);
- if ($uu==0)
- $uu = strcasecmp($a['addr'], $b['addr']);
- return $uu;
- }
- //-------------------------------------
- function restruct($arr) {
- $newarr = array();
- foreach ($arr as $el) {
- if (!array_key_exists($el['domain'],$newarr)) {
- $newarr[$el['domain']]=array();
- }
- $newarr[$el['domain']][]= $el['addr'];
- }
- return $newarr;
- }
- //-------------------------------------
- $func = create_function('$el','echo $el."<br/>";');
- $arr = array_filter($arr, 'filt');
- $arrdoms = array_map('getdom',$arr);
- $arrcomb = array_map('combarrs', $arr, $arrdoms);
- usort ($arrcomb,'zsort');
- $arrcomb4 = restruct($arrcomb);
- echo '<pre>'.print_r($arrcomb4,true).'</pre>';
- //array_walk($arrdoms, $func);
- //-------------------------------------------------------------------------------------
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement