POV-Ray : Newsgroups : povray.off-topic : Lamp me one : Re: Lamp me one Server Time
14 Nov 2024 18:20:52 EST (-0500)
  Re: Lamp me one  
From: Invisible
Date: 5 Feb 2008 09:27:35
Message: <47a87257@news.povray.org>
Invisible wrote:
> I just learned PHP. I feel unclean...

And here's a small pointless toy I just developed...

<html>
<head>
   <title>PHP Test #4 (Output)</title>
</head>
<body>

<h1>PHP Test #4 (Output)</h1>
<p>
<a href="Test4-In.html">Return to input form</a>
</p>

<h2>Input</h2>
<pre><?php echo htmlspecialchars($_POST['code']); ?></pre>
<p>Length: <?php echo strlen($_POST['code']); ?> characters.</p>

<h2>Frequency Table</h2>
<?php
$table = array();
$in = $_POST['code'];

for ($pos=0; $pos < strlen($in); $pos++)
{
   $symbol = $in[$pos];
   if (isset($table[$symbol])) $table[$symbol] = $table[$symbol] + 1;
   else $table[$symbol] = 1;
}
?>

<table border="1">
   <tr>
     <th>Symbol</th>
     <th>Count</th>
     <th>Probability</th>
     <th>Bits</th>
   </tr>
<?php
foreach ($table as $symbol => $count)
{
   echo '<tr><td align="center">‘<code>';
   echo htmlspecialchars($symbol);
   echo '</code>’</td><td align="right">';
   echo $count;
   echo '</td><td align="right">';
   echo (int)($count / strlen($in) * 100);
   echo '%</td><td align="right">';
   echo abs(log($count / strlen($in)) / log(2));
   echo '</td></tr>';
   echo "\n";
}
?>
   <tr>
     <td align="center">Total</td>
     <td align="right"><?php echo strlen($in); ?></td>
     <td align="right">100%</td>
     <td align="right">0</td>
   </tr>
</table>

</body>
</html>

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.