- var_dump: documentation ( source)
- preg_replace: documentation ( source)
<?php
$s = 'width=222<iframe >width=222<embed boo width=222>fdgwidth=700dfg</embed>sfsdfsdf</iframe>';
$matches = array();
var_dump( preg_replace('~(.*<[^>]+\swidth=["\']?)(\d+)(["\']?[^>]*>.*)~', '${1}---${3}', $s) );