Same deal as my first post from today’s Open Hack London event – these are (very) rough notes, please let me know of clarifications, questions or comments.
Hacking with PHP, Rasmus Lerdorf
Goal of talk: copy and pastable snippets that just work so you don’t have to fight to get things that work [there’s not enough of this to help beginners get over that initial hump]. The slides are available at http://talks.php.net/show/openhack and these notes are probably best read as commentary alongside the code examples.
[Since it’s a hack day, some] Hack ideas: fix something you use every day; build your own targeted search engine; improve the look of search results; play with semantic web tools to make the web more semantic; tell the world what kind of data you have – if a resume, use hResume or other appropriate microformats/markup; go local – tools for helping your local community; hack for good – make the world a better place.
SearchMonkey and BOSS are blending together a little bit.
What we need to learn
parsing XML: simpleXML_load_file() – can load entire URL or local file.
Attributes on node show up as array. Namespace attributes call children of node, name namespace as argument.
Now know how to parse XML, can get lots of other stuff.
Context extraction service, Yahoo – doesn’t get enough attention. Post all text, gives you back four or five key terms – can then do an image search off them. Or match ads to webpages.
Can use get or post (curl) – usually too much for get.
If you can figure out these six lines of code, you can write anything in the world. How every modern web application works.
‘There’s nothing to building web applications, you just have to break everything down into small enough chunks that it all becomes trivial’.
AJAX in 30 seconds.
Inline comments in code would help for people reading it without hearing the talk at the same time.
load maps API, create container (div) for the map, then fill it.
Form – on submit call return updateMap(); with new location.
YGeoRSS – if have GeoRSS file… can point to it.
GeoPlanet – assigns a WOE ID to a place. Locations are more than just a lat long – carry way more information. Basically gives you a foreign key. YQL is starting to make the web a giant database. Can make joins across APIs – woeid works as fk.
YQL – ‘combines all the APIs on the web into a single API’.
Add a cache – nice to YQL, and also good for demos etc. Copy and paste cache function from his slides – does a local cache on URL. Hashed with md5. Using PHP streams – #defn. Adding a cache speeds up developing when hacking (esp as won’t be waiting for the wifi). [This is a pretty damn good tip cos it’s really useful and not immediately obvious.]
XPath on URL using PHP’s OAuth extension
SearchMonkey – social engineering people into caring about semantic data on the web. For non-geeks, search plug-in mechanism that will spruce up search results page. Encourages people to add semantic data so their search result is as sexy as their competitors – so goal is that people will start adding semantic data.
‘If you’re doing web stuff, and don’t know about microformats, and your resume doesn’t have hResume, you’re not getting a job with Yahoo.’
Question: how are microformats different to RDFa?
Answer: there are different types of microformats – some very specific ones, eg hResume, hCal. RDFa – adding arbitrary tags to page. even if no specific way to describe your data. But there’s a standard set of mark-ups for a resume so can use that. if your data doesn’t match anything at microfomats.org then use RDFa or erdf (?).