<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="code.xsl" ?>
<dns4.nl>
<voorbeeld>
<title>php script in een plaatje om de alexa ranking te tonen.</title>
<verwijzende_link>http://www.dns4.nl/pagina/php_code/alexa_rank_script.html</verwijzende_link>
<informatie>


</informatie>
<programma_code>
<![CDATA[
<!-- de code begint vanaf hier.

<?php
	function LoadPNG($imgname){
		$url="http://google.com";
		$im = @imagecreatefrompng($imgname);
		$achtergond = imagecolorallocate($im, 0,0, 0);
		imagecolortransparent($im, $achtergrond);
		$witte = imagecolorallocate($im, 150, 150, 222);
		class functions {
			function format_number ($number='', $divchar = ',', $divat = 3) {
				$decimals = '';
				$formatted = '';
				if (strstr($number, '.')) {
					$pieces = explode('.', $number);
					$number = $pieces[0];
					$decimals = '.' . $pieces[1];
				} else {
					$number = (string) $number;
				}
				if (strlen($number) <= $divat)
					return $number;
					$j = 0;
				for ($i = strlen($number) - 1; $i >= 0; $i--) {
					if ($j == $divat) {
						$formatted = $divchar . $formatted;
						$j = 0;
					}
					$formatted = $number[$i] . $formatted;
					$j++;
				}
				return $formatted . $decimals;
			}
		}	
		class rank extends functions {
			var $url;
			var $alexa_rank;
			function rank ($url) {
				$this->url = $url;
				$this->url = preg_replace('/http\:\/\//si', '', $this->url);
				$this->alexa_rank = $this->__alexa_rank();
			}
			function __alexa_rank () {
				$url = 'http://data.alexa.com/data?cli=10&dat=snbamz&url=' . urlencode($this->url);
				$v = file_get_contents($url);
				preg_match('/\<popularity url\="(.*?)" TEXT\="([0-9]+)"\/\>/si', $v, $r);
				return ($r[2]) ? $r[2] : '0';
			}
		}
		error_reporting(E_ALL ^ E_NOTICE);
		$rank = new rank($url);
		$r = array($rank->url,$rank->format_number($rank->alexa_rank));
		$desite=$r[0];
		$derang=$r[1];
		imagestring($im, 5, 53, 11, $derang, $witte);
		imagestring($im, 3, 53, 25, $desite, $witte);
		return $im;
	}
	header('Content-Type: image/png');
	$img = LoadPNG('alexa.png');
	imagepng($img);
	imagedestroy($img);
?>

de code is hier geeindigd.
// -->
]]>

</programma_code>
<code_link>http://www.dns4.nl/pagina/alle_tekst_files.html</code_link>
</voorbeeld>
</dns4.nl>
