'; // if we know what attribute we need to replace // we need to search and replace the string: $attribute=XXX or $attribute="XXX" // and replace it with an empty string $pattern = '/' . $attribute . '="([^"]+?)"/'; return preg_replace($pattern, '', $string); }