Jump to content

string formatting


dannyd

Recommended Posts

Why use preg_replace() for a simple task, when using sprintf() will work fine:

<?php
        $strs = array('00030','00005','02830','00002','00200');
        foreach ($strs as $str)
                echo $str . "<br>\n";
        echo "<br>\n";
        foreach ($strs as $str)
                echo sprintf("%d",$str) . "<br>\n";
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/92114-string-formatting/#findComment-471769
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.