Archive for snippets
Javascript / jQuery get first class name of element
February 16th, 2012 • 2 comments javascript, jQuery, snippets
Need to get the first class name of an element? Simple! Imagine having a link with 3 class names
<a id="myelement" href="http://google.com" class="class1 class2 class3">Go to google</a>
$('a#myelement').attr('class').split(' ')[0]
Will result in: class1
Facebook Error Message: Requires valid next URL.
June 16th, 2010 • 1 comment facebook, php, snippets
Tags: api error, invalid parameter
Let me start with asking you a few questions!
- Are you having issues with the Facebook API?
- Are you constantly getting the error message “API Error Code: 100 API Error Description: Invalid parameter Error Message: Requires valid next URL.“?
- Are you using the latest official Facebook PHP class?
- Are you redirecting using the PHP header() function?
Well, I might have a solution for you. When calling the function getLoginUrl in the Facebook PHP class, the function will return a HTML encoded string. When outputing this string to your browser, it is rendered/decoded by a browser and this will convert all “safe” charachters to their textual equivalent. This makes that “&” becomes “&” and “%20″ becomes ” “.
However, when using the header() function in PHP, this url will not be rendered/decoded and you are basically sending out a garbled request.
Original
getLoginUrl($params);
header('Location:' . $url);
Solution:
getLoginUrl($params);
$url = str_replace('&','&',urldecode($url));
header('Location:' . $url);
xdebug trace file parser
November 18th, 2009 • 6 comments freebies, php, snippets, software, xdebug

When I am trying to optimize my PHP code, one of my prefered tools is xdebug. It provides me with excellent error messages, outputs code tracing files & insight into memory usage.
By using kcachegrind or webgrind – wincachegrind crashes *all* the time – to parse the cachegrind files created by xdebug, you get a good idea of what your code is doing most of the time. It’ll show you which functions are called, by who, which arguments are passed and tons more. Check it out.
Now, there was one small thing I couldn’t find anywhere. A program to parse the trace files that xdebug generates. True, xdebug already provides the option to output this information into HTML, but it’s not really what I was looking for. I want to get quick information in the blink of an eye! That’s why I have created my own trace file parser, based on PHP of course.
Read more »
Drupal 5 Views Module Breaks Block Administration
July 31st, 2009 • 1 comment drupal, hack, snippets, views
While working on a new Drupal 5.19 powered website that has the latest view module enabled, my coworker noticed a strange feature. Once you activated more than one template and tried to switch over to manage the blocks on an other template than garland you will see it switching to garland 50% of the time. Read more »
memcache_connect() [function.memcache-connect]: Can’t connect to localhost:11211
May 11th, 2009 • 4 comments memcache, memcached, php, snippets
Encountered this error? It could be as simple as switching the host from localhost to 127.0.0.1
before:
<?php
$memcache_obj = memcache_connect('localhost', 11211);
after:
<?php
$memcache_obj = memcache_connect('127.0.0.1', 11211);
