WebSockets are the new cool boys in town, but the specs are in a very early state and so it’s hard to keep up to date with the different browser implementations …
July 22, 2010
July 15, 2010
Google Ranking Checker Class in PHP
The only goal for an SEO is a good or very good google ranking. To ensure this you have to monitor your rankings and compare it to the positions of your competitors. With the Google AJAX Search API and my little PHP Class you can easy build a Google Ranking Checker …
The class needs an Google API key for the AJAX Search API (get it here) … it’s just one field and a click and you can start. You can check multiple keywords for multiple domains or urls, just pass this two arrays to the check() method.
July 11, 2010
HTML5 WebSockets Example
HTML5 WebSockets makes it possible to open a persistent connection to a server within a web-browser via javascript.
February 18, 2010
E-Mail Links wirksam schützen
Einige einfache Methoden wie man E-Mail Links schützen kann. Aber die richtig guten Ideen sind dann in einem Kommentar-Link zu finden.
November 7, 2009
Google Closure Compiler with PHP
Today Google released their new Closure Compiler, you can use it to optimize and minify your javascripts.
June 30, 2009
PHP 5.3 fertig!
Die neue PHP Version ist nun endgültig fertig und freigegeben. Zu den neuen Funktionen gehören Closures, Funktionsobjekte und Lambda-Funktionen, die native MySQL Library, namespaces und late static binding. Aber für mich am wichtigsten sind die Performance-Verbesserungen, PHP 5.3 wird ca. 1,5x so schnell sein wie 5.2 und durch den neuen Garbage Collector deutlich weniger Speicher verbrauchen.
June 14, 2009
Einstieg: Zend_Service_Twitter
Einen eigenen Twitter-Client schreiben geht mit der richtigen Library ganz schnell. Im aktuellen Zend Framework ist die Komponente Zend_Service_Twitter enthalten die sehr einfach zu verwenden ist.
Zuerst mal anmelden und die Daten des angemeldeten Benutzers ausgeben:
require_once 'Zend/Service/Twitter.php'; $twitter = new Zend_Service_Twitter($username, $password); if ($user = $twitter->account->verifyCredentials()) { foreach($user as $k => $v) { echo "$k: $v<br />"; } }
Die Leute denen man folgt inkl. Bild und Link ausgeben:
foreach($twitter->user->friends() as $user) { printf('<div class="l"><a href="http://twitter.com/%s"><img width="48" height="48" src="%s" /></a></div>', $user->screen_name, $user->profile_image_url); }
Und so einfach kann man seine eigenen Replies ausgeben lassen:
foreach($twitter->status->replies() as $message) { echo "<div>"; printf('<a href="http://twitter.com/%s"><img width="48" height="48" src="%s" /></a><p>%s %s</p>', $message->user->screen_name, $message->user->profile_image_url, $message->text, $message->created_at); echo "</div>"; }
Für so ziemlich alles gibt es bereits die Methoden die man nur mehr aufrufen muss und dann SimpleXML-Objekte zurückbekommt. Ein etwas größeres Beispiel könnt ihr unter folgenden URL finden: http://bohuco.net/dev/twitter.php
Natürlich werden die Twitter-Zugangsdaten nicht mitgespeichert! (siehe Quelltext)
January 23, 2009
LOC and Author Stats with Subversion
Very, very simple author and LOC statistic with Subversion blame function and PHP. So you can see how many lines are already in the repository and which user coded it.
[sourcecode language="php"]
// include only this folders
$dirs[] = '/var/www/portal/application';
$dirs[] = '/var/www/portal/html/scripts/k2';
$dirs[] = '/var/www/portal/html/scripts/service';
$dirs[] = '/var/www/portal/html/styles';
// function from php.net
function listFiles( $from = '.') {
if(! is_dir($from))
return false;
$files = array();
$dirs = array( $from);
while( NULL !== ($dir = array_pop( $dirs))) {
if( $dh = opendir($dir)) {
while( false !== ($file = readdir($dh))) {
if( $file == '.' || $file == '..')
continue;
$path = $dir . '/' . $file;
if( ! is_dir($path)) {
$ext = substr($file, strrpos($file, '.')+1);
// include file extensions
if (in_array($ext, array('html','php','phtml','inc','js','css'))) {
$files[] = $path;
}
} else {
// exclude subdirs
if (! in_array($file, array('fckeditor'))) {
$dirs[] = $path;
}
}
}
closedir($dh);
}
}
return $files;
}
$files = array();
foreach($dirs as $dir) {
$files = array_merge($files, listFiles($dir));
}
$stats = array();
foreach($files as $file) {
$tmpFile = '/tmp/blame.tmp';
exec("svn --non-interactive --username myuser --password mypass blame $file > $tmpFile”, $o, $r);
$output = file($tmpFile);
foreach($output as $line) {
$parts = split(‘[ ]‘, trim($line));
$author = $parts[1];
if (! isset($stats[$author])) {
$stats[$author] = 0;
}
$stats[$author]++;
}
}
var_dump($stats);
var_dump(count($files));
[/sourcecode]
November 26, 2008
Zend Framework 1.7 released
Wohhh … da geht was weiter … schon wieder ein neues Release von Zend Framework. Mit Twitter und jQuery Support. Da hab ich schon wieder was zu tun die nächsten Abende.
Außerdem gibt’s einen neuen Performance-Guide in der Doku.
November 4, 2008
PHP Arrays: "power set" and all permutations
Found in the online-version of PHP Cookbook from O’Reilly.
“Power set” = combinations of all or some elements
On one of our development servers (php 5.2.0) we had a problem with the original version of this function, it looked like an endless loop till memory limit exceeded. Here is the rewritten version from Srdjan:
[sourcecode language='php']
public function powerSet($array) {
$results = array(array());
foreach ($array as $j => $element) {
$num = count($results);
for($i=0; $i<$num; $i++) {
array_push($results, array_merge(array($element), $results[$i]));
}
}
return $results;
}
[/sourcecode]
All permutations
[sourcecode language='php']
function pc_permute($items, $perms = array( )) {
if (empty($items)) {
print join(‘ ‘, $perms) . “\n”;
} else {
for ($i = count($items) – 1; $i >= 0; –$i) {
$newitems = $items;
$newperms = $perms;
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
pc_permute($newitems, $newperms);
}
}
}
[/sourcecode]