doutangliang7769
2016-12-28 17:48
浏览 38
已采纳

如何爆炸substr - PHP Captcha

I need your help to explode a substr function. It's for a captcha, need to have every character separate, to apply different color on each character.

Thank you.

$authorizedChar= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

$nbChar = rand(4, 8);

$text = substr(str_shuffle($authorizedChar), 0, $nbChar);

图片转代码服务由CSDN问答提供 功能建议

我需要你的帮助来爆炸一个substr函数。 这是一个验证码,需要将每个字符分开,在每个字符上应用不同的颜色。

谢谢。

  $ authorizedChar  =“abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”; 
 
 $ nbChar = rand(4,8); 
 
 $ text = substr(str_shuffle($ authorizedChar),0,$ nbChar); 
    
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • du4822 2016-12-28 17:52
    已采纳

    Use str_split()

    var_dump(str_split('testing'));
    

    Would return:

    array (size=7)
      0 => string 't' (length=1)
      1 => string 'e' (length=1)
      2 => string 's' (length=1)
      3 => string 't' (length=1)
      4 => string 'i' (length=1)
      5 => string 'n' (length=1)
      6 => string 'g' (length=1)
    
    已采纳该答案
    打赏 评论
  • doubi6898 2016-12-28 17:53

    Why not use simple for-loop here

    $authorizedChar= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $nbChar = rand(4, 8);
    $text = substr(str_shuffle($authorizedChar), 0, $nbChar);
    for($i=0; $i<strlen($text); $i++)
      echo $text[$i]."<br />";
    
    打赏 评论

相关推荐 更多相似问题