Version: 1.0
Type: Function
Category: Algorithms
License: BSD License
Description: Convert strings into papertape
<?
//
// Papertape Convertor v1.0 by Edwin Groothuis (edwin@mavetju.org)
//
// $Id: papertape.php,v 1.1 2001/09/04 12:01:19 mavetju Exp $
//
// If you didn't get this file via http://www.mavetju.org, please
// check for the availability of newer versions.
//
// See LICENSE for distribution issues. If this file isn't in
// the distribution, please inform me about it.
//
// Feel free to use this yourself.
//
//
// Usage:
//
// start_papertape()
// to_papertape(...)
// finish_papertape()
// stop_papertape()
//
function start_papertape() {
return "___________";
}
function finish_papertape() {
return "| o. o |";
}
function stop_papertape() {
return "___________";
}
function to_papertape($char) {
$ret="|";
$char=ord($char);
for ($i=7;$i>=0;$i--) {
if ($i==2)
$ret.="."; // feed hole
if (($char & (1<<$i)) !=0)
$ret.="o";
else
$ret.=" ";
}
$ret.="|";
return $ret;
}
if ($text) {
echo "<pre> ",start_papertape(),"\n";
$len=strlen($text);
for ($i=0;$i<$len;$i++) {
$d=$text[$i];
echo "$d ",to_papertape($d),"\n";
}
echo " ",finish_papertape(),"\n";
echo " ",stop_papertape(),"</pre>\n";
}
?>
<form method="post" action="<? echo $PHP_SELF; ?>">
<input type="text" name="text" value="<? echo $text; ?>">
</form>