XML "slashback"

Status
Not open for further replies.

Telematx

Ars Tribunus Militum
2,841
If you have PHP:

code:<HR>
Code:
<?PHP <P>$host    = "www.arstechnica.com";
$path    = "/news_source.html";<P>$fp = fsockopen ($host, 80, $errno, $errstr, 30);<P>if (!$fp) {
	echo "$errstr ($errno)
\n";
} else {
	fputs($fp, "GET " . $path . " HTTP/1.0\r\n\r\n");
	$string	= "";
	while(!feof($fp)) {
		$pagetext = fgets($fp,228);
		$source .= chop($pagetext);
	}
	fputs($fp,"Connection: close\r\n\r\n");
	fclose($fp);<P>	$arSource = explode("<h2>",$source);
	for ($i=0; $i<count($arSource); $i++) {
		$pos = strpos($arSource[$i],"</h2>");
		if ($pos === false) {
			//nothing
		} else {
			$arHeadlines[count($arHeadlines)] = substr($arSource[$i], 0, $pos);
		}
	}<P>	echo "<B>Headlines from ArsTechnica:</B>
\n";
	for ($i=0; $i<count($arHeadlines); $i++) {
		echo "<LI><a href='http://www.arstechnica.com'>" .$arHeadlines[$i]. "</a>
\n";
	}
}<P>?>

http://thisoldhaus.com/tests/ars_headlines.php

There's probably a simpler way to do it, but I'm having a hard time figuring our regular expressions. Also, you'd probably want to cache the headlines on your server, and only update every couple of hours or so.
 
Status
Not open for further replies.