Pregex匹配问题

I am trying to use preg_replace on a string to get rid of empty attributes however the entire string is being wiped out.

The string I am doing replacement on looks like this:

 <input type="text" name="username" id="username" class="required" size="20" maxlength="40" value="" />

Here is the code I am trying to use:

    $defaults = array(
        'cols' => '60',
        'class' => '',
        'currentValue' => '',
        'default' => '',
        'group' => '',
        'id' => '',
        'maxlength' => '',
        'name' => '',
        'options' => array(),
        'rows' => '00',
        'size' => '60',
        'text' => '',
        'type' => 'text',
        'value' => ''
    );
    $inputHTML = '<input type="text" name="username" id="username" class="required" size="20" maxlength="40" value="" />';
    $inputHTML = preg_replace( '/(' . implode( '|', array_keys( $defaults ) ) , ')=""/g', '', $inputHTML );

The array is being used since I need for other portions of the code.

Any ideas why the string comes back blank?

You have a , instead of a . in your preg_replace call. Also, you have a "" in your regex, so it will only catch empty attributes (oh, that was exactly what you wanted to do).

Corrected line:

$inputHTML = preg_replace( '/(' . implode( '|', array_keys( $defaults ) ) . ')=""/', '', $inputHTML );

Working example: http://ideone.com/sO9K9S