How to delete characters in a string?

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?

+5
source share
4 answers

only cast will do it efficiently

echo (int) $var;
+11
source

If the format is the same for all lines ([numbers] .jpg), you can do:

intval('0130799.jpg', 10);

intval () in the manual

+3
source

substr, strpos, substr .

, .

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 , .

0

preg_replace('/^0+/m','',$sourcestring);

^ - ( m )

0+ 1 .

.

Regexr

0

All Articles