Jose
Jose

Reputation: 73

How to do a substring in PHP?

I have this project in PHP, and I need to get rid of the "0" at start.

This the line of code I have that already takes of all the letters and keeps all the numbers.

$Number = mysqli_real_escape_string($connect, preg_replace('/[^0-9]/','',$worksheet->getCellByColumnAndRow(2,$row)->getValue()));

The output will be = "0123004567" I want to remove the first number "0" with substring(Like in java). Can you show me how to do it in PHP?

Upvotes: 0

Views: 316

Answers (1)

wogsland
wogsland

Reputation: 9508

The function you're looking for is

$Number = ltrim($Number,'0');

That will only remove zeroes at the beginning of the string.

Upvotes: 5

Related Questions