There are a few different ways to check the selected items to the given string. Given a learning process, I'd suggest iteratively and using an array to contain the answers already given by the user.
You can iterate a string as it is simply an char array. It is mutable in PHP as well, so you can modify it iteratively.
$sWord = 'This is a word.';
$iLen = strlen($sWord);
for ($i = 0; $i < $iLen; ++$i)
printf("Char at %d is %s" . PHP_EOL, $i, $sWord[$i]);
Now during iteration, you can check the char against an array of user selected chars. If $sWord[$i] is in the selected array of chars, then show that letter. Otherwise, show *. You may want to push the space char as well otherwise you won't be able to see the spaces.
There are several ways to see if a value is in an array. Iterative is one, but there are functions for this as well. See here for a list of all the array functions: http://www.php.ca/manual/en/book.array.php
Finally, you need to figure out a way to persist previously selected chars. If you know sessions, that's a simple matter of creating an array within the sessions that has these. If not, you can pass an array through a hidden field via serialize() and unserialize() to read and write them. Then you simply add the newly provided char to the array of chars passed, and when they are presented with the form again you can provide it with the array serialized again. This way you get to always keep it in an array.
Add some simple logic beyond there to indicate that all letters were chosen, and even to indicate when a letter has already been chosen.
Hopefully that gives you some hints where to go. Like I said, there are several other options as well for you. str_[i]replace does accept arrays, but you'll need to reverse the logic in order to set *'s where there is no corresponding match as opposed to what is set. range() can be used to populate a list of chars a-z for example, and array_diff functions can be used to pull things out. This is actually a better solution overall, but doesn't have any looping involved, so I guess that depends on if you are doing an assignment for something like looping.