<?php $text = "background: url(img/back.gif)"; $pattern = '/^background: url\(img\/back.gif\)/'; $text = preg_replace($pattern, "background: url(../img/back.gif)", $text); echo $text; ?>