Zo ik ben Zend Certified Engineer.
Check mijn blogpost over de voorbereiding en het examen op de Netlash-blog.
Zo ik ben Zend Certified Engineer.
Check mijn blogpost over de voorbereiding en het examen op de Netlash-blog.
When sending HTML-mails through PHP you'll see that some email-clients (like: gmail) will strip al the styles you defined in an external stylesheet or in a style-tag.
You can't expect the users of your application will define all the styles inline (some WYSIWYG-editors have that functionality), so it would be nice if there was a way to grab the HTML, set the CSS and just get the HTML but with all styles defined inline.
So here is CSSToInlineStyles, this class enables you to do this.
Well, it's pretty straight forward. After setting the HTML (and CSS), the class will read the CSS build an array that contains all the rules sorted by their specifity.
The HTML will be loaded as a DOMDocument.
When that's done, each rule will be looped. The CSS-selector will be converted into a XPath-query. If the query returns an element a style-attribute will be added, all defined CSS-rules will be added into this style attribute.
So, get the class and enjoy.
When scrapping HTML-pages it can be usefull to get elements based on CSS-selectors. Therefore I wrote a nifty function that builds a XPath-query that can be used to select the elements in a DOMXPath-document.
The function can be found below:
<?php
/**
* Convert a CSS-selector into an xPath-query
*
* @return string
* @param string $selector The CSS-selector
*/
function buildXPathQuery($selector)
{
// redefine
$selector = (string) $selector;
// the CSS selector
$cssSelector = array( // E F: Matches any F element that is a descendant of an E element
'/(\w)\s+(\w)/',
// E > F: Matches any F element that is a child of an element E
'/(\w)\s*>\s*(\w)/',
// E:first-child: Matches element E when E is the first child of its parent
'/(\w):first-child/',
// E + F: Matches any F element immediately preceded by an element
'/(\w)\s*\+\s*(\w)/',
// E[foo]: Matches any E element with the "foo" attribute set (whatever the value)
'/(\w)\[([\w\-]+)]/',
// E[foo="warning"]: Matches any E element whose "foo" attribute value is exactly equal to "warning"
'/(\w)\[([\w\-]+)\=\"(.*)\"]/',
// div.warning: HTML only. The same as DIV[class~="warning"]
'/(\w+|\*)?\.([\w\-]+)+/',
// E#myid: Matches any E element with id-attribute equal to "myid"
'/(\w+)+\#([\w\-]+)/',
// #myid: Matches any E element with id-attribute equal to "myid"
'/\#([\w\-]+)/'
);
// the xPath-equivalent
$xPathQuery = array( '\1//\2',
'\1/\2',
'*[1]/self::\1',
'\1/following-sibling::*[1]/self::\2',
'\1 [ @\2 ]',
'\1[ contains( concat( " ", @\2, " " ), concat( " ", "\3", " " ) ) ]',
'\1[ contains( concat( " ", @class, " " ), concat( " ", "\2", " " ) ) ]',
'\1[ @id = "\2" ]',
'*[ @id = "\1" ]'
);
// return
return (string) '//'. preg_replace($cssSelector, $xPathQuery, $selector);
}
?>
In a post that will be published in the near future you 'll see why I really needed it.
Listenr.tv is een website waarop je je favoriete muziek kan bekijken.
Ik luister graag naar muziek, ik ontdek ook graag nieuwe muziek. Daarvoor gebruik ik Last.fm.
Naast naar muziek luisteren kan je via de muziekzenders TMF, Jim of MTV ook heel wat muziek leren kennen door ernaar te kijken. Helaas voor de mensen (zoals ik) die geen mainstream hiphop, boenk-boenk liefhebbers zijn kan je op deze zenders enkel terecht tijdens de thema-uurtjes en daar spelen ze dan enkel de gekende muziek.
Daarom leek het me leuk en handig om de kracht van Last.fm en YouTube te combineren om voor iedereen een persoonlijke muziekzender te maken.
De website kan je op twee manieren benaderen.
Zodra je een playlist hebt gekozen kan je beginnen kijken naar jouw favoriete muziek.
Veel plezier!
Kan er iemand (liefst iemand met een beetje verstand in zijn hoofd) van De Lijn mij uitleggen welk nut de eindhalte in Wondelgem heeft?
Omdat het zo'n schitterend weer is waag ik mij niet op de baan met de moto. Daarom neem ik 's avonds Lijn 1 richting Evergem. Ofwel hebben ze bij De Lijn iets tegen mij of ik slaag er altijd in op een tram terecht te komen die slechts tot Wondelgem rijdt.
Na de eindhalte van Wondelgem moet ik slechts 2 haltes verder afstappen. Met de tram is dat iets van een 5minuten, tot aan de eindhalte (slechts 1 halte verder dan de mijne) is het volgens mij nog iets van een 2minuten rijden.

Als jullie nu eens altijd tot aan de eindhalte van Evergem rijden, dan hoef ik nooit meer 20min te staan wachten in Wondelgem om dan nog 5minuten op de tram te zitten.
Of begrijp ik het weer niet zo goed?
Als je al eens in aanraking komt met grote projecten dan kan de Slow Query Log een hele openbaring zijn. In deze log komen alle queries die langer duren dan een ingesteld aantal seconden en een minimum aantal rijen moet verwerken.
The slow query log consists of all SQL statements that took more than long_query_time seconds to execute and required at least min_examined_row_limit rows to be examined.
Maar omdat alle trage queries hierin terechtkomen is het niet altijd makkelijk om uit te maken welke nu juist de queries zijn die je best aanpakt.
Via de mensen van Openminds had ik vernomen dat er een script was die deze log gaat parsen en je kan vertellen welke queries juist aandacht vragen.
Het script analyseert de log door te gaan kijken welke queries er meerdere keren voorkomen. Daarbij vervangen ze de variabele data zodat je een goed beeld krijgt.
Hoe installeer je het script:
sudo mv path/to/download /usr/bin/mysql_slow_log_parser
sudo chmod +x /usr/bin/mysql_slow_log_parser
mysql_slow_log_parser path/to/slow_query.log
Kleine disclaimer: Wil je je database en queries tot in de puntjes optimaliseren? Neem dan een specialist onder de arm, zij kunnen je bijstaan met raad en daad. Een database-specialist weet beter dan welke tool ook hoe je database of queries kan optimaliseren