PHP - 列出带有网址的号码

标签 php numbers

像这样的 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/

相关文章:

php - mysql_real_escape_string 的问题

php - 改进 MySQL LIKE 运算符

javascript - 检查输入字符串是否包含javascript中的数字

javascript - 在带有 if 语句的函数中检查某物是否为数字

Mysql存储一个数字而不是值集

c++ - 如何将两个逗号放在一个 float 中?

php - 使用 AJAX 调用 PHP 函数?

php - 连接表并显示 city.name

java - 完美的数字

php - 在php中选择format mysql to highchart