mkosmosports Posted April 4, 2007 Share Posted April 4, 2007 Hey, I have the following string: $test = "12/12/2007" What would be the most effective way of removing the forward slashes to come up with a "12122007" result? Thanks! Link to comment https://forums.phpfreaks.com/topic/45574-getting-rid-of-forward-slashes/ Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 Use the str_replace() function: <?php $test = "12/12/2007" $test = str_replace('/','',$test); echo $test; ?> You can also use a combination of date() and strtotime() <?php $test = "12/12/2007"; $test = date('mdY',strtotime($test)); echo $test; ?> Ken Link to comment https://forums.phpfreaks.com/topic/45574-getting-rid-of-forward-slashes/#findComment-221301 Share on other sites More sharing options...
mkosmosports Posted April 4, 2007 Author Share Posted April 4, 2007 Beautiful, much quicker than other options I had considered like trim or preg_replace..... Thanks! Link to comment https://forums.phpfreaks.com/topic/45574-getting-rid-of-forward-slashes/#findComment-221308 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.