Advertisement
verrary

Php_Functions

Jun 19th, 2015
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.10 KB | None | 0 0
  1. <?php ini_set('display_errors', 1);//ini_set('error_reporting', E_ALL);
  2. function corl($Ur){$ch = curl_init();curl_setopt($ch, CURLOPT_HEADER, false);
  3. curl_setopt($ch, CURLOPT_VERBOSE, 0);
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);  
  6. curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0');
  7. curl_setopt($ch, CURLOPT_URL,$Ur);
  8. $target_url = curl_exec($ch); curl_close($ch); // تخزين الصفحة في متغير نصي  
  9. return $target_url;}
  10. // معرفة العناصر المكررة بعد استدعائها في الحلقة
  11. $f=-1;$inArr= Array();
  12.  
  13. function rep($vlu) { global $f,$inArr; // استخدمت قلوبل حتى
  14. if (in_array($vlu,$inArr)) return true ; //   التحقق ادا كان القيمة مكررة ام لا
  15. else  { $inArr[$f++]=$vlu;  // ضع القيمة في مصفوفة المقارنة
  16.     return false;  }} // ارجاع خطاء ادا القيمة غير مكررة
  17.  
  18.  
  19.  $start = microtime( true  )  ;    function excute() {  global $start;  $end = microtime(  true ) ;  $time =  number_format(  (  $end - $start  ), 3  )  ;   return  $time  ;        }  
  20. function array_key_filter(  $array , $callback) {
  21.     $f = array_filter(array_keys( $array ), $callback);
  22.     return array_intersect_key( $array , array_flip( $f ) ); }
  23. function video (  $arr  )  {
  24. /*    [thumbnail] => https://i.ytimg.com/vi/hZmoMyFXDoI/mqdefault.jpg
  25.    [title] => [MV] BOL4(볼빨간사춘기) _ Some(썸 탈꺼야)
  26.    [title_short] => [MV] BOL4(볼빨간사춘기) _ Some(썸...
  27.    [username] => 1theK (원더케이)
  28.    [profile] => https://www.youtube.com/channel/UCweOkPb1wVVH0Q0Tlj4a5Pw
  29.    [views] => 33511996
  30.    [date] => 28/09/17
  31.    [time] => 00:03:07
  32.    [more] => https://www.youtube.com/watch?v=hZmoMyFXDoI
  33.    [embed_url] => http://www.youtube.com/embed/hZmoMyFXDoI?autoplay=1                 */
  34. //echo '<iframe allowFullScreen="allowFullScreen" src="'. $arr[ 'embed_url'  ]  .'?ecver=1&amp;iv_load_policy=3&amp;rel=0&amp;showinfo=0&amp;yt:stretch=16:9&amp;autohide=0&amp;color=red&amp;width=560&amp;width=560" width="560" height="315" allowtransparency="true" frameborder="0"></iframe> '  ;
  35.        }
  36. //j  الاسرع لتحميل صفحة  parse_url( $domain )['path']
  37. function  sockopen(   $domain    )  {  $contents  = NULL ; $i = 0 ;  
  38.  $host  = parse_url( $domain )['host']     ;  
  39.    $url = explode (  $host ,  $domain )[1]   ;
  40.  $fp    = @fsockopen(  "ssl://$host" , 443 , $errno, $errstr , 3 )   ;
  41.         //                echo '<br>  fsockopen  In '.excute().' Seconds'.'<br/>';  
  42.      if(   !$fp    )  {   $contents   .= $errstr. ' (' . $errno . ')<br />'   ;  echo (    $contents    )   ;  }
  43.   else   {
  44. $out = "GET ". $url." HTTP/1.1\r\n"   ;
  45.  $out .= "Host: ".$host."\r\n"    ;
  46. $out .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5\r\n"    ;
  47. //$out .= "Referer: https://www.google.com/\r\n";
  48. $out .= "Connection: Close\r\n\r\n"     ;    
  49.        //    var_dump (    $out    )   ;
  50. fwrite(  $fp   ,   $out    )   ;      //   fwrite  fgets         exit()  ;
  51. while(  !feof(  $fp  )   )     {       // $i++; if (  $i > 2  ) break ;
  52.  $contents .=   fread  (  $fp   , 480   ) ;   }
  53.    // $contents  =   fread  (  $fp, 14096   )  ;
  54.   fclose( $fp )    ;  
  55.           }
  56. // echo  $i  ;    
  57. //  return    explode ( "Connection: close\r\n\r\n"  , $contents )[1]   ;      //   "Connection: close\r\n\r\n"
  58.   return     $contents   ;      //   "Connection: close\r\n\r\n"
  59.  
  60.     }
  61.  
  62. function time_elapsed_string(  $ptime  ) {
  63.     //var_dump(time());
  64.     //var_dump($ptime);
  65.     $etime = time(  ) - $ptime;
  66.     //var_dump($etime);
  67.     if (    $etime < 1  ) {
  68.         return '0 seconds';
  69.     }
  70.  
  71.     $a = array(   12 * 30 * 24 * 60 * 60 => 'year',
  72.         30 * 24 * 60 * 60 => 'month',
  73.         24 * 60 * 60 => 'day',
  74.         60 * 60 => 'hour',
  75.         60 => 'minute',
  76.         1 => 'second'
  77.                 )  ;
  78.  
  79.     foreach (  $a   as   $secs    =>   $str   )    {
  80.         $d = $etime / $secs;
  81.         //var_dump($d);
  82.         if   (   $d >= 1   ) {
  83.             $r = round(   $d  );
  84.             return $r . ' ' . $str . (  $r > 1 ? 's' : ''  ) . ' ago';
  85.         }
  86.     }
  87. }
  88.  
  89.  
  90. ///////////////////////////////////////////
  91.  
  92. /**
  93.  * @param $timestampl
  94.  * @param $timestamp2
  95.  * @param $time_unit
  96.  * @return bool|float
  97.  */
  98.  
  99. function time_difference($timestampl, $timestamp2, $time_unit)
  100. {
  101.     // determine the difference between two dates
  102.     $timestampl = intval($timestampl);
  103.     $timestamp2 = intval($timestamp2);
  104.     if ($timestampl && $timestamp2)
  105.     {
  106.         $time_lapse = $timestamp2 - $timestampl;
  107.  
  108.         $seconds_in_unit = array(
  109.             "second" => 1,
  110.             "minute" => 60,
  111.             "hour" => 3600,
  112.             "day" => 86400,
  113.             "week" => 604800,
  114.         );
  115.  
  116.         if ($seconds_in_unit[$time_unit])
  117.             return round($time_lapse/$seconds_in_unit[$time_unit]);
  118.     }
  119.     return false;
  120. }
  121.  
  122. /**
  123.  * Outputting formatted date-time
  124.  * @param $date_time
  125.  * @return string
  126.  */
  127. function date_time_out($date_time)
  128. {
  129.     $current_time = time();
  130.     $time_diff = time_difference($date_time, $current_time, 'minute');
  131.     $date_diff = time_difference($date_time, $current_time, 'day');
  132.     $result = '';
  133.     if ($time_diff < 60) return $time_diff . ' minute' . ($time_diff==1)?'':'es' . ' ago';
  134.     else if ($time_diff >= 60 AND $date_diff == 0) $result.= 'Today';
  135.     else if ($date_diff == 1) $result.= 'Yesterday';
  136.     else $result.= date("Y-m-d", $date_time);
  137.     $result.= ' at '. date('H:i', $date_time);
  138.     return $result;
  139. }
  140.  
  141. /**
  142.  * Outputting text with limited words count
  143.  * @param $text
  144.  * @param $words_count
  145.  * @return string
  146.  */
  147. function short_text_out($text, $words_count) {
  148.     $arr = explode(' ', $text);
  149.     $count_arr = count($arr);
  150.     $arr = array_slice($arr, 0, $words_count);
  151.     $text = implode(' ', $arr);
  152.     if ($count_arr > $words_count) $text.= '...';
  153.     unset($arr);
  154.     unset($count_arr);
  155.     return strip_tags($text);
  156. }
  157.  
  158. /**
  159.  *  Return the youtube video duration
  160.  *  @param $youtube_time
  161.  *  @return time
  162.  */
  163. function covtime($youtube_time){
  164.     $start = new DateTime('@0'); // Unix epoch
  165.     $start->add(new DateInterval($youtube_time));
  166.     return $start->format('H:i:s');
  167. }
  168.  
  169.    
  170.       ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement