project3 Posted February 8, 2008 Share Posted February 8, 2008 I have a string and want to repace the first 14 digits with x's how would I go about doing that? Link to comment https://forums.phpfreaks.com/topic/90121-str_replace-help/ Share on other sites More sharing options...
kenrbnsn Posted February 8, 2008 Share Posted February 8, 2008 I would use a combination of the substr() and str_replace() functions: <?php $str = "this is a very long string that is longer that 14 characters long"; $x = 'xxxxxxxxxxxxxx'; $new_str = str_replace(substr($str,0,14),$x,$str); echo $str . '<br>' . $new_str; ?> Ken Link to comment https://forums.phpfreaks.com/topic/90121-str_replace-help/#findComment-462097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.