I have a lot of lines, and I need to remove the "0" at the beginning of the line, but what is the best way to do this because it is an example of lines:
0130799.jpg //I need to get 130799 0025460.jpg //I need to get 25460
Now I use the substr function, but I think it is more efficient if I use Regex no?
only cast will do it efficiently
echo (int) $var;
If the format is the same for all lines ([numbers] .jpg), you can do:
intval('0130799.jpg', 10);
intval () in the manual
substr, strpos, substr .
substr
strpos
, .
00000ddddddd.jpg( ) , preg_match.
, http://writecodeonline.com/php/
preg_match('/([1-9][0-9]+)\.jpg/', "I have a file called 0000482080.jpg somewhere", $matches); echo "I like to call it: {$matches[0]}";
, intval , .
intval
preg_replace('/^0+/m','',$sourcestring);
^ - ( m )
^
m
0+ 1 .
0+
.
Regexr