Page 1 of 1

Fairly simple program for learning semaphore

Posted: Fri Jun 04, 2010 11:39 am
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 :)

Re: Fairly simple program for learning semaphore

Posted: Fri Jun 04, 2010 11:46 am
by phdatabase
You're right, it would be fairly simple. I'd do it with a translating array.

Re: Fairly simple program for learning semaphore

Posted: Fri Jun 04, 2010 2:31 pm
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

Re: Fairly simple program for learning semaphore

Posted: Fri Jun 04, 2010 5:15 pm
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

Re: Fairly simple program for learning semaphore

Posted: Sat Jun 05, 2010 3:55 pm
by agapetos
Thanks guys - works like a charm! :)