像这样的 php 示例:
for ($i=1; $i<=20; $i++){
$url = "http://example.org/12".$i."<br />";
echo $url;
}
我想要输出:
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
感谢所有能帮助我的人:D
最佳答案
您可以使用 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;
}
您还可以使用 sprintf()
for ($i=1; $i<=20; $i++){
$i = sprintf("%02d",$i);
$url = "http://example.org/12".$i."<br />";
echo $url;
}
关于PHP - 列出带有网址的号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20019907/