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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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.