<?php $string = "1,5,154,32,123,132"; $need = "32"; echo preg_replace("#(^\d|\,|^)".$need."(\,|^|^\d)#",",",$string); ?>