dominod Posted June 30, 2010 Share Posted June 30, 2010 Hi I want to remove words that end with : within a string. For example if I write "test: 1234" it will remove "test:" and only echo "1234" Can anyone help me with this? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/206282-removing-words-in-a-string/ Share on other sites More sharing options...
salathe Posted June 30, 2010 Share Posted June 30, 2010 What happened to the space after "test:"? Quote Link to comment https://forums.phpfreaks.com/topic/206282-removing-words-in-a-string/#findComment-1079145 Share on other sites More sharing options...
dominod Posted June 30, 2010 Author Share Posted June 30, 2010 sorry .. make it echo " 1234" then If thats what u mean? Quote Link to comment https://forums.phpfreaks.com/topic/206282-removing-words-in-a-string/#findComment-1079153 Share on other sites More sharing options...
XeNoMoRpH1030 Posted June 30, 2010 Share Posted June 30, 2010 Sounds like a job for a regular expression. Quote Link to comment https://forums.phpfreaks.com/topic/206282-removing-words-in-a-string/#findComment-1079156 Share on other sites More sharing options...
dominod Posted June 30, 2010 Author Share Posted June 30, 2010 What do u mean? Quote Link to comment https://forums.phpfreaks.com/topic/206282-removing-words-in-a-string/#findComment-1079157 Share on other sites More sharing options...
kenrbnsn Posted June 30, 2010 Share Posted June 30, 2010 Are there more words in the string? If not, you can use the explode function: <?php $str = "word: 1234"; $tmp = explode(':',$str); echo $tmp[1]; ?> or <?php $str = 'word: 1234'; list($dmy,$word) = explode(':',$str); echo $word; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/206282-removing-words-in-a-string/#findComment-1079213 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.