Fairly simple program for learning semaphore

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
agapetos
Forum Newbie
Posts: 4
Joined: Thu Sep 24, 2009 4:04 pm

Fairly simple program for learning semaphore

Post by agapetos »

Hi,
I am new with php, thou I did a few php websites. I have started making a web-site for learning semaphore flag system and morse code. Here is what my program should do.
Extract a random word from the mysql, and than use some php function to replace each letter with a corresponding picture (a man holding his flags in some way, that would signal that letter, or in the case of morse - series of dots and lines corresponding to that letter).
I have searched but still did not find the function that could solve this, thou I am sure that it is something very very easy, but ... I still can't find it.
Does someone know how? thanks :)
User avatar
phdatabase
Forum Commoner
Posts: 83
Joined: Fri May 28, 2010 10:02 am
Location: Fort Myers, FL

Re: Fairly simple program for learning semaphore

Post by phdatabase »

You're right, it would be fairly simple. I'd do it with a translating array.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Fairly simple program for learning semaphore

Post by Weirdan »

Code: Select all

$morse = array(
//..........
 's' => '· · ·',
 'o' => '— — —',
//..........
);
$string = 'SOS';
echo str_replace(array_keys($morse), array_values($morse), strtolower($string)); // morse code is case-insensitive, thus the strtolower() call
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Fairly simple program for learning semaphore

Post by Jonah Bron »

Weirdan wrote:

Code: Select all

$morse = array(
//..........
 's' => '· · ·',
 'o' => '— — —',
//..........
);
$string = 'SOS';
echo str_replace(array_keys($morse), array_values($morse), strtolower($string)); // morse code is case-insensitive, thus the strtolower() call
Or

Code: Select all

$morse = array(
//..........
 's' => '<img src="semaphor-pos-s.jpg" />',
 'o' => '<img src="semaphor-pos-o.jpg" />',
//..........
);
$string = 'SOS';
echo str_replace(array_keys($morse), array_values($morse), strtolower($string)); // semaphor is case-insensitive, thus the strtolower() call
agapetos
Forum Newbie
Posts: 4
Joined: Thu Sep 24, 2009 4:04 pm

Re: Fairly simple program for learning semaphore

Post by agapetos »

Thanks guys - works like a charm! :)
Post Reply