Search code examples
phpcaptchaexplodesubstr

How to explode 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);

Solution

  • 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)