Question: `$image` variable gives this code (when `echo` is used):

```
<img src="/image.png" width="100" height="147" alt="" class="some_class" />

```

* `width`, `height`, `src` and `class` 
attributes can be different.

What should we do:

1. **remove** `width` and `height` from `$image`
2. replace `alt=""` with `alt="Poster"`

Thanks.

Answer: 
I'd use regular expressions to do this.

```
// Replace width="..." and height="..." with nothing
$variable = preg_replace('/(width|height)\s*=\s*"[^"]*"/i', '', $image);

// Replace alt="..." with alt="Poster"
$variable = preg_replace('/alt\s*=\s*"[^"]*"/i', 'alt="Poster"', $variable);

```

This method is not dependant on the order of the attributes, which of the some other answers are. Also note that the second regular expressions will replace `alt="<any string here>"` with `alt="Poster"`. It should be easy enough to change it to only replace `alt=""` though.
will also replace `<embed width="x">` which is wrong. We need to catch only with `<img>` tag