magnetica Posted March 15, 2010 Share Posted March 15, 2010 Hi all Hope you can help. I have a string and I wanted to trim anything that is past the colon ( : ) in the string. E.g. $string = "Magnetica: hell this would be a comment"; I want to get it so the output is: Magnetica This is my code so far: $text = "Magnetica: hello this is a comment"; var_dump($text); $trimmed = rtrim($text, ":"); var_dump($trimmed); But this doesn't work, any ideas? Thanks, Magnetica Link to comment https://forums.phpfreaks.com/topic/195280-trimming-a-string/ Share on other sites More sharing options...
trq Posted March 15, 2010 Share Posted March 15, 2010 $string = substr($string, 0, strpos($string, ':')); Link to comment https://forums.phpfreaks.com/topic/195280-trimming-a-string/#findComment-1026231 Share on other sites More sharing options...
magnetica Posted March 15, 2010 Author Share Posted March 15, 2010 $t = explode(":", $text); echo $t['0']; Which will be quicker? Your probably Link to comment https://forums.phpfreaks.com/topic/195280-trimming-a-string/#findComment-1026233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.