example php like this:
for ($i=1; $i<=20; $i++){
$url = "http://example.org/12".$i."<br />";
echo $url;
}
i want output :
http://example.org/1201
http://example.org/1202
http://example.org/1203
http://example.org/1204
http://example.org/1205
http://example.org/1206
http://example.org/1207
http://example.org/1208
http://example.org/1209
http://example.org/1210
http://example.org/1211
http://example.org/1212
.......
http://example.org/1220
Thanks for everybody who can help me :D
You can use str_pad()
for ($i=1; $i<=20; $i++){
$i = str_pad($i, 2, "0", STR_PAD_LEFT);
$url = "http://example.org/12".$i."<br />";
echo $url;
}
You can also use sprintf()
for ($i=1; $i<=20; $i++){
$i = sprintf("%02d",$i);
$url = "http://example.org/12".$i."<br />";
echo $url;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With