Well if you are trying to replace width=”” where “” means empty, you do not need to use “*” when using str_replace, as str_replace do not support regular expression. In that case you function will be as :
function replace_content_on_the_fly($text){
$replace = array(
// 'words to find' => 'replace with this'
'width=""' => 'width="730px"',
'height=""' => 'height="486px"'
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
If you want to replace all width height what so ever is between “”, you need to use preg_replace
function replace_content_on_the_fly($text){
$newWidth = 730;
$newHeight = 486;
$text = preg_replace(
array('/width="\d+"/i', '/height="\d+"/i'),
array(sprintf('width="%d"', $newWidth), sprintf('height="%d"', $newHeight)),
$text);
return $text;
}