You can do this a couple of different ways. If you're wanting to use the variable $replacement
that you created, you can use preg_replace_callback
to do that. But it would be far simpler to just use it in the expression like this:
// CREATE AN EXAMPLE STRING
$string = '<input type="text" size="15" name="coupon" id="coupon" value="xyz" />
<input type="text" size="15" name="coupon" id="coupon" />';
// DO THE REPLACEMENT
$string = preg_replace('~<input type="text" size="15" name="coupon" id="coupon"( value="([A-Z0-9]+)")? />~i', '<div class="coupon"><input type="text" value="$2" /></div>', $string);
This will output the following:
<div class="coupon"><input type="text" value="xyz" /></div>
<div class="coupon"><input type="text" value="" /></div>