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?