shaggycap Posted December 20, 2006 Share Posted December 20, 2006 I need to remove everything up to and inlcuding the -, ie the following string15e-6812 needs to be converted to 6812.[code]$string = '15e-6812'; preg_replace($reg_expression_goes_here, '', $string);[/code]And the number of characters before the minus sign varies, so is it possible to match 'to the left of and including' the minus sign?Thanks. Link to comment https://forums.phpfreaks.com/topic/31346-match-remove-part-of-string/ Share on other sites More sharing options...
Orio Posted December 20, 2006 Share Posted December 20, 2006 [code]<?php$str = "23532523sad-6665d";echo substr($str,strpos($str, "-")+1); //output- "6665d"?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/31346-match-remove-part-of-string/#findComment-145081 Share on other sites More sharing options...
Nicklas Posted December 21, 2006 Share Posted December 21, 2006 There´s no need for regular expressions to do what you want, use explode() insteadex[code=php:0]$str = '15e-6812';list( ,$str) = explode('-', $str);[/code]$str now holds the value 6812 Link to comment https://forums.phpfreaks.com/topic/31346-match-remove-part-of-string/#findComment-145530 Share on other sites More sharing options...
weknowtheworld Posted January 9, 2007 Share Posted January 9, 2007 I think you must use ltrim(). For e.g :-$number = '0310';$number = ltrim( $number, "\0x30" );echo $number;output: 10. Link to comment https://forums.phpfreaks.com/topic/31346-match-remove-part-of-string/#findComment-156797 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.