S
S
Sergey Beloventsev2018-03-15 13:09:04
PHP
Sergey Beloventsev, 2018-03-15 13:09:04

How to complete a line?

A string consisting of numbers comes conditionally into string examples

125687
159
1368

it is necessary that the line has 6 characters, but if a line comes with fewer digits, then you need to fill in 0, so I don’t understand how to do it yet.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-03-15
@Sergalas

php.net/manual/en/function.str-pad.php

A
Antarit, 2018-03-15
@Antarit

Depending on how to set the task, with the addition of 0xD34F, he suggested that if you want to get a line like 000159 from line 159, then it is better to use sprintf...
php.net/manual/ru/function.sprintf.php
$num = 159;
sprintf('%06d', $num);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question