/*
Simple CSV Reader
So, a few ground rules:
- Rows must end with a newline
- Rows cannot have newlines in them
- All values must be enclosed in double quotes.
- Double quotes are allowed inside values.
If the file is not formatted according to these rules then
the world as we know it will cease to exist.
Available public methods:
- log(): Returns an array log if something is out of order.
Have a good day.
*/
class CSVreader
{
private $log;
public function __construct($filename = NULL)
{
if ($filename)
{
$this->open($filename);
}
}
private function open($filename)
{
if ( ! file_exists($filename)) die ("File $filename does not exist.");
if ( ! is_readable($filename)) die ("File $filename is not readable.");
$lines = file($filename, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
$fields = $this->line_values( array_shift($lines) );
$fieldCount = count($fields);
foreach($lines as $key => $values)
{
$values = $this->line_values($values);
$valueCount = count($values);
$line = $key + 2;
if ($valueCount < $fieldCount)
{
$missing = $fieldCount - $valueCount;
for ($x=0; $x<$missing; $x++) $values[] = '(n/a)';
$this->log_message($line, "$missing ".($missing==1?'value is':'values are')." missing");
}
if ($valueCount > $fieldCount)
{
$tooMany = $valueCount - $fieldCount;
$this->log_message($line, "There ".($tooMany==1?"is 1 value":"are $tooMany values")." too many");
}
$i = 0;
foreach ($values as $val)
{
if (empty($val))
{
$this->log_message($line, "There is an empty value");
}
$fieldName = $fields[$i];
if ( ! $fieldName) continue;
$this->{$line}->$fields[$i] = $val;
$i++;
}
}
}
public function log()
{
return $this->log;
}
private function line_values(&$line)
{
$line = trim($line);
$values = preg_split('/"([ \t]+)?,([ \t]+)?"/', $line);
foreach ($values as &$val)
{
$val = trim($val, '"');
}
return $values;
}
private function log_message($line, $message)
{
$this->log[] = "Line $line: $message";
}
}
/*
Example.txt:
"firstname","surname"
"Jane","Doe"
"John","Doe"
*/
$csv = new CSVreader('Example.txt');
foreach ($csv as $line => $row) {
echo "$line: {$row->firstname} {$row->surname}<br />\n";
}
<?php
// Grab the favicon of a domain using Google s2 Converter
// Put this in your php file and then call it like:
// http://yourdomain.com/file.php?url=somedomain.com
function getFavicon(){
$linkurl = $_GET['url'];
$linkurl = str_replace("http://",'',$linkurl); // remove protocol from the domain
$imgurl = "http://www.google.com/s2/favicons?domain=" . $linkurl;
echo '<img src="' . $imgurl . '" width="16" height="16" />';
}
getFavicon();
?>
/*
Function used to return flickr short url from a photo id.
example of usage
var shortFlickrURL:String = 'www.flic.kr/p/' + Base58Encoder.encode(Number('4725679319') );
/// returns www.flic.kr/p/8cAkPD
/// short url for this full url http://www.flickr.com/photos/ninjaparade/4725679319/
*/
package {
/**
* @author ninjaparade
*/
public class Base58Encoder {
public static function encode( num : Number ) : String
{
var alphabet : String = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ' ;
var base_count : int = alphabet.length;
var encode : String = "";
while(num >= base_count) {
var div : int = num / base_count;
var mod : int = (num - base_count * Math.round(div) );
encode = alphabet.charAt(mod) + encode;
num = Math.round(div);
}
if(num)
{
encode = alphabet.charAt(num) + encode;
}
return encode;
}
}
}
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}]
@="{1531d583-8375-4d3f-b5fb-d23bbd169f22}"