<?php $strtoreplace = "here is a link <href=test.php?id=1&1234=2345>terst</a>;" $search = "&"; $replace = "#"; $text = preg_replace($search, $replace, $strtoreplace); echo $text ; ?>