Jump to content

Help with school project


evankennedy

Recommended Posts

Hello, I am working on a project for my server scripting class, and I need some help.

 

First off, I want to show you what we already know in this class so you don't say to do some crazy thing we haven't learned yet.

  • If Else statements
  • Variables
  • Arrays
  • For loops

I think thats mostly what we know except for a few basic things.

 

What I am trying to do is to output a specified letter through asterics.  Here is are a few examples of outputs.

 

*****    *****    *****

*    *    *      *    *

*****    *****    *

*    *    *      *    *

*    *    *****    *****

    A          B          C

 

now a few things come to mind when you think about this.  The first is probably just saying if ($letter=="a"){echo "Asterics for A";}

 

I already am aware of this method and I am wondering if there is a way to do this with an array or with a for loop.

 

Thanks

Link to comment
Share on other sites

that is hard to do with loop (very loooong)or array but if its ok not to use them then maybe you can try this

$a1='****';
$a2='***';
$a3='**';
$a4='*';
$a5 = '*  *'
$a6= '  *';

//print A then 
echo $a1.'<br>';
echo $a5.'<br>';
echo $a1.'<br>';
echo $a5.'<br>';
echo $a5.'<br>';

you cant have your code dynamic but like one loop to cover all letter you have to have a code for each letters

 

 

Link to comment
Share on other sites

<?php

$output = "abcdefghi";

$letterTemplate[1] = '*****';
$letterTemplate[2] = '*      *';
$letterTemplate[3] = '*        ';
$letterTemplate[4] = '       *';
$letterTemplate[5] = '      **';
$letterTemplate[6] = '***    ';
$letterTemplate[7] = '*   &nbsp**';
$letterTemplate[8] = '    *    ';

$letterLayout['a'] = '12122';
$letterLayout['b'] = '12121';
$letterLayout['c'] = '13331';
$letterLayout['d'] = '12221';
$letterLayout['e'] = '13131';
$letterLayout['f'] = '13633';
$letterLayout['g'] = '13721';
$letterLayout['h'] = '22122';
$letterLayout['i'] = '18881';

$outputLetters = str_split($output);

foreach( $outputLetters as $letter ) {

$lines = str_split( $letterLayout[strtolower($letter)] );

foreach( $lines as $line ) {
	echo $letterTemplate[$line] . '<br />';
}

echo "-----<br />";
}

?>

 

Just continue to fill out the arrays for the templates and the layouts and it will print any combination of letters you would like. You probably want to wrap the letter output in a dive or a table in order to make it go horizontal across the page, other then that the code should work flawlessly. Any questions just let me know.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.