$pattern = '<img src\="\$post\[avatarurl\]".*/>'; $replacement = '<div id="myDiv">content</div>'; echo preg_replace($pattern, $replacement, $vbulletin->templatecache['postbit']);