morowind
morowind

Reputation: 302

PHP reversing the order of the numbers from right to left and integrating them into a string

I have a display for a weight scale. I need to send following string '000000=.' to serial port display if there is no weight value.

for display I need to reverse order of number:

scale weight: 236
display string will be : 632000=.

I need a php function to do that- it's is possible?

Upvotes: 0

Views: 155

Answers (2)

Santhosh Paloor
Santhosh Paloor

Reputation: 31

$input = 236;
$output = str_pad(strrev($input),6,'0').'=.';

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

Upvotes: 2

Liauchuk Ivan
Liauchuk Ivan

Reputation: 1993

If I understand you right: This function revert string

$input = 1234;
$output = strrev($input);
for ($i = strlen($output); $i < 6; $i++) {
    $output .= '0';
}
$output .= "=.";

I think, now, I have understand you right.

Upvotes: 2

Related Questions