l!m!t Posted June 29, 2008 Share Posted June 29, 2008 Hi - I hope someone can help me with this. I am trying to strip off the last value from the last underscore I seem to only be able to get the first underscore on. I just want the last underscore removed, so.. 12_13_45_99 would be 12_13_45 Basically anything from the last underscore removed. $new_cat= preg_replace("/_(.*)/i","",'12_13_45_99'); Any help would be great. Link to comment https://forums.phpfreaks.com/topic/112499-solved-srtip-off-end-of-string-preg_replace/ Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 <?php $var = "12_13_45_99"; echo substr($var, 0, strrpos($var, "_")); ?> Link to comment https://forums.phpfreaks.com/topic/112499-solved-srtip-off-end-of-string-preg_replace/#findComment-577640 Share on other sites More sharing options...
l!m!t Posted June 29, 2008 Author Share Posted June 29, 2008 Thanks br0ken worked great.! Appreciated! Link to comment https://forums.phpfreaks.com/topic/112499-solved-srtip-off-end-of-string-preg_replace/#findComment-577646 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.