Can’t get str_pad() to properly replace characters in a string

I’m trying to replace some characters from a string using str_pad and I can’t get it to work at all and I have no idea why it doesn’t work.

Code:

<?php
$t = "abcdefghij";
$t = str_pad($t, 4, "0");
echo $t;
?>

Expected:

abcd000000

Result:

abcdefghij 

I also tried:

$t = sprintf("%04x", $t);

Which results in:

0000
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s