小编Hal*_*jan的帖子

从字符串中提取未知数字

我有一个字符串"padding: 0px 0px 0px 0px".但数字是未知的,所以可以是0,5,10,25,100或其他...

将每个变量提取到变量的最佳方法是什么?

(i.e. 
$number1 = first number
$number2 = second number
$number3 = third number
$number4 = fourth number)
Run Code Online (Sandbox Code Playgroud)

css php string extract

0
推荐指数
1
解决办法
420
查看次数

带有while循环的php函数

我有一个生成随机组合的函数.

我的函数看起来像这样:

  function random_gen($length) {
  $random= "";
  srand((double)microtime()*1000000);
  $char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  $char_list .= "abcdefghijklmnopqrstuvwxyz";
  $char_list .= "1234567890";
  // Add the special characters to $char_list if needed

  for($i = 0; $i < $length; $i++)
  {
    $random .= substr($char_list,(rand()%(strlen($char_list))), 1);
  }
  return $random;
}

$new_url = random_gen(6);
Run Code Online (Sandbox Code Playgroud)

现在我想有一个while循环来检查我的数据库中是否已经存在$ new_url ...

然后插入如下结果:

mysql_query("INSERT INTO lank (url, code) VALUES ('$url', '$new_url')"); 
Run Code Online (Sandbox Code Playgroud)

除了while循环,我得到了一切工作.而我只是想弄清楚如何做到这一点......

php function while-loop

-1
推荐指数
1
解决办法
4925
查看次数

标签 统计

php ×2

css ×1

extract ×1

function ×1

string ×1

while-loop ×1