The Social Issues Research Center: Guide to Flirting. This is actually a serious and detailed article. More interesting than you'd think.
On Slashdot, Conceptual Models of a Program?. This post has a link to a book I haven't yet come across, which looks like it might be a very good read. How to Design Programs: An Introduction to Programming and Computing, by MIT press.
What's neat about PHP is that they keep giving us more features, and I keep using them. Case in point: the cURL extention -- damn useful. I just used it for the first time today. It understands Chunked Transfer Encoding for me - good deal.
I just looked at my site in Internet Explorer, and it's gross. I've been spoiled by Mozilla.
I'm in the process of writing my own RSS aggregator. Naturally, I wanted to be able to use the new RSS auto-discovery method which has evolved over the past few days. Mark Pilgrim made some Javascript bookmarklets and a Python implementation to do this, but I needed a PHP implementation, so I wrote one
. First the code, and then I'll explain:
<?php
function getRSSLocation($html, $location){
if(!$html or !$location){
return false;
}else{
#search through the HTML, save all <link> tags
# and store each link's attributes in an associative array
preg_match_all('/<link\s+(.*?)\s*\/?>/si', $html, $matches);
$links = $matches[1];
$final_links = array();
$link_count = count($links);
for($n=0; $n<$link_count; $n++){
$attributes = preg_split('/\s+/s', $links[$n]);
foreach($attributes as $attribute){
$att = preg_split('/\s*=\s*/s', $attribute, 2);
if(isset($att[1])){
$att[1] = preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1]);
$final_link[strtolower($att[0])] = $att[1];
}
}
$final_links[$n] = $final_link;
}
#now figure out which one points to the RSS file
for($n=0; $n<$link_count; $n++){
if(strtolower($final_links[$n]['rel']) == 'alternate'){
if(strtolower($final_links[$n]['type']) == 'application/rss+xml'){
$href = $final_links[$n]['href'];
}
if(!$href and strtolower($final_links[$n]['type']) == 'text/xml'){
#kludge to make the first version of this still work
$href = $final_links[$n]['href'];
}
if($href){
if(strstr($href, "http://") !== false){ #if it's absolute
$full_url = $href;
}else{ #otherwise, 'absolutize' it
$url_parts = parse_url($location);
#only made it work for http:// links. Any problem with this?
$full_url = "http://$url_parts[host]";
if(isset($url_parts['port'])){
$full_url .= ":$url_parts[port]";
}
if($href{0} != '/'){ #it's a relative link on the domain
$full_url .= dirname($url_parts['path']);
if(substr($full_url, -1) != '/'){
#if the last character isn't a '/', add it
$full_url .= '/';
}
}
$full_url .= $href;
}
return $full_url;
}
}
}
return false;
}
}
?>
The function takes two arguments. The raw HTML and the location you got it from. The location has to be there so relative links to the RSS file can be resolved.
First, PHP doesn't have an SGML parser built in like Python seems to, so I had to get all the <link> tags myself. A few regular expressions and some simple string splitting made it all real easy. Next, you cycle through all the links found, figure out which one is the RSS file, resolve it to an absolute URL if necessary, and return it.
I'll gladly take any suggestions for improving the code, and if I change it I'll update it here. Hope this helps.
Update: if you need a function to retrieve the HTML for you, feel free to use mine.
<?php
function getFile($location){
$ch = curl_init($location);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
?>
This uses PHP's interface to the excellent cURL library, so this requires PHP 4.02 or higher.
Update: cool, mentioned on Scripting News! But oy! My name is spelled wrong. Later: he's fixed it, thanks Dave! Also seen on dive into mark and Keith Gaughan.
Update (6/6/02): Fixed a small bug where the RSS location returned would be incorrect if the RSS location had a query string with equals signs.
$att = preg_split('/\s*=\s*/s', $attribute);
had to be
$att = preg_split('/\s*=\s*/s', $attribute, 2);
so that it would only return up to two values, and not split on any more equals signs. Found while retrieving the RSS feed for Langreiter.com
.
Update (6/19/02): small improvement thanks to Pepino.
Update (7/26/02): added a timeout to the getFile function.
Update (4/15/03): made it work with error_reporting(E_ALL), and changed the way it resolves relative URLs (see comments for more info).
Update (9/15/03): Note: this code is public domain.
PHP's strtotime function doesn't read full ISO 8601 date/times??
I really gotta try DataVision one of these days. If this thing works like it's supposed to, I may be able to use this instead of writing innumerable reports in PHP. It's worth a try, and regardless, it looks like a very link-worthy open source project.
DataVision is a database reporting tool similar to Crystal Reports. Reports can be viewed and printed from the application or output as HTML, LaTeX2e, XML, DocBook, or tab- or comma-separated text files. From the LaTeX2e and DocBook output files you can in turn produce PDF, text, HTML, PostScript, and more.
Report descriptions are stored as XML files. This means you can not only use the DataVision GUI, but you may also edit reports using your favorite text editor.
DataVision is written in Java. It runs under Linux, Windows, various flavors of BSD and Unix, and Mac OS X. It can generate reports from Oracle, PostgreSQL, MySQL, Informix, hsqldb, Microsoft Access, and any other database with available JDBC drivers.
Eric conveys an emotion (emotioneric.com).
The concept here is simple, this is a humor-oriented interactive website. You request an emotion (or reasonable facsimile), and I will try and act it out for you. The frame on the left shows the currently filled emotions. The list in the right frame shows requests that are waiting to be filled. Sure, so some of these may not be emotions per se, we're just having fun here. So what are you waiting for?
Funny stuff.
new⇒Javascript clone function
?!code:language=javascript
varparent = { name : "jake", age :"26"};
...
Jake: May 8, 10:05am