<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Danostuporstar's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 09:04:02 GMT</pubDate>
    <description>DZone Snippets: Danostuporstar's Code Snippets</description>
    <item>
      <title>php ffl_HttpGet()</title>
      <link>http://snippets.dzone.com/posts/show/530</link>
      <description>If your server has allow_url_fopen disabled, use this as a workaround for file() ... hell use it anyway and get the http headers as a bonus.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/**&lt;br /&gt; FUNCTION: ffl_HttpGet()&lt;br /&gt; * Perform a HTTP Get Request.&lt;br /&gt; *&lt;br /&gt; * ffl_HttpGet uses fsockopen() to request a given URL via HTTP&lt;br /&gt; * 1.0 GET and returns a three element array.  On success, array&lt;br /&gt; * key 'body' contains the body of the request's reply and key&lt;br /&gt; * 'header' contains the reply's headers.  On error, the keys&lt;br /&gt; * returned are 'errornumber' and 'errorstring' from&lt;br /&gt; * fsockopen()'s third and fourth arguments.  In either case,&lt;br /&gt; * key 'url' contains an array such as returned from parse_url()&lt;br /&gt; * after the input url has been massaged a bit.&lt;br /&gt; *&lt;br /&gt; * {@source }&lt;br /&gt; *&lt;br /&gt; * @param string $url URL to fetch.&lt;br /&gt; * @param boolean $followRedirects Optionally follow &lt;br /&gt; * 'location:' in header, default true.&lt;br /&gt; * @return array 'header', 'body', 'url' OR 'errorstring',&lt;br /&gt; * 'errornumber', 'url'.&lt;br /&gt; */&lt;br /&gt;function ffl_HttpGet( $url, $followRedirects=true ) {&lt;br /&gt;    $url_parsed = parse_url($url);&lt;br /&gt;    if ( empty($url_parsed['scheme']) ) {&lt;br /&gt;        $url_parsed = parse_url('http://'.$url);&lt;br /&gt;    }&lt;br /&gt;    $rtn['url'] = $url_parsed;&lt;br /&gt;&lt;br /&gt;    $port = $url_parsed["port"];&lt;br /&gt;    if ( !$port ) {&lt;br /&gt;        $port = 80;&lt;br /&gt;    }&lt;br /&gt;    $rtn['url']['port'] = $port;&lt;br /&gt;    &lt;br /&gt;    $path = $url_parsed["path"];&lt;br /&gt;    if ( empty($path) ) {&lt;br /&gt;            $path="/";&lt;br /&gt;    }&lt;br /&gt;    if ( !empty($url_parsed["query"]) ) {&lt;br /&gt;        $path .= "?".$url_parsed["query"];&lt;br /&gt;    }&lt;br /&gt;    $rtn['url']['path'] = $path;&lt;br /&gt;&lt;br /&gt;    $host = $url_parsed["host"];&lt;br /&gt;    $foundBody = false;&lt;br /&gt;&lt;br /&gt;    $out = "GET $path HTTP/1.0\r\n";&lt;br /&gt;    $out .= "Host: $host\r\n";&lt;br /&gt;    $out .= "Connection: Close\r\n\r\n";&lt;br /&gt;&lt;br /&gt;    if ( !$fp = @fsockopen($host, $port, $errno, $errstr, 30) ) {&lt;br /&gt;        $rtn['errornumber'] = $errno;&lt;br /&gt;        $rtn['errorstring'] = $errstr;&lt;br /&gt;        return $rtn;&lt;br /&gt;    }&lt;br /&gt;    fwrite($fp, $out);&lt;br /&gt;    while (!feof($fp)) {&lt;br /&gt;        $s = fgets($fp, 128);&lt;br /&gt;        if ( $s == "\r\n" ) {&lt;br /&gt;            $foundBody = true;&lt;br /&gt;            continue;&lt;br /&gt;        }&lt;br /&gt;        if ( $foundBody ) {&lt;br /&gt;            $body .= $s;&lt;br /&gt;        } else {&lt;br /&gt;            if ( ($followRedirects) &amp;&amp; (stristr($s, "location:") != false) ) {&lt;br /&gt;                $redirect = preg_replace("/location:/i", "", $s);&lt;br /&gt;                return ffl_HttpGet( trim($redirect) );&lt;br /&gt;            }&lt;br /&gt;            $header .= $s;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    fclose($fp);&lt;br /&gt;&lt;br /&gt;    $rtn['header'] = trim($header);&lt;br /&gt;    $rtn['body'] = trim($body);&lt;br /&gt;    return $rtn;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 30 Jul 2005 10:34:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/530</guid>
      <author>danostuporstar (Dano Stuporstar)</author>
    </item>
    <item>
      <title>php glob_rsort_modtime()</title>
      <link>http://snippets.dzone.com/posts/show/392</link>
      <description>&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;/**&lt;br /&gt; FUNCTION: glob_rsort_modtime()&lt;br /&gt; * Glob reverse sorted by file modification time.&lt;br /&gt; *&lt;br /&gt; * Returns an array of files matching the given glob pattern, sorted &lt;br /&gt; * by their modification times in descending order.  The array keys&lt;br /&gt; * hold the filepath and the values hold the mtime.  On error, array&lt;br /&gt; * will be indexed and contain 'false' and an error message.&lt;br /&gt; *&lt;br /&gt; * {@source}&lt;br /&gt; *&lt;br /&gt; * @param string $patt Pattern to search, including glob braces.&lt;br /&gt; * @return array filename =&gt; mtime OR false, 'errormsg'.&lt;br /&gt; */&lt;br /&gt;function glob_rsort_modtime( $patt ) {&lt;br /&gt;    if ( ( $files = @glob($patt, GLOB_BRACE) ) === false ) {&lt;br /&gt;        return array( false, 'Glob error.');&lt;br /&gt;    }&lt;br /&gt;    if ( !count($files) ) {&lt;br /&gt;        return array( false, 'No files found.');&lt;br /&gt;    }&lt;br /&gt;    $rtn = array();&lt;br /&gt;    foreach ( $files as $filename ) {&lt;br /&gt;        $rtn[$filename] = filemtime($filename);&lt;br /&gt;    }&lt;br /&gt;    arsort($rtn);&lt;br /&gt;    reset($rtn);&lt;br /&gt;    return $rtn;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$files = glob_rsort_modtime( './*' ) ;&lt;br /&gt;echo'&lt;pre&gt;'.print_r($files, true).'&lt;/pre&gt;';&lt;br /&gt;?&gt; &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 17 Jun 2005 14:01:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/392</guid>
      <author>danostuporstar (Dano Stuporstar)</author>
    </item>
    <item>
      <title>Hello World Tcl</title>
      <link>http://snippets.dzone.com/posts/show/387</link>
      <description>Mostly just playing with this site which seems pretty cool.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;&lt;br /&gt;# Next line restarts using tclsh \&lt;br /&gt;exec tclsh "$0" "$@"&lt;br /&gt;&lt;br /&gt;puts "Hello World."&lt;br /&gt;exit&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 16 Jun 2005 01:34:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/387</guid>
      <author>danostuporstar (Dano Stuporstar)</author>
    </item>
  </channel>
</rss>
