1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

str_replace(): Argument #2 ($replace) must be of type array|string, float given

Discussion in 'General discussion' started by Hoangviphb999, Oct 18, 2021.

  1. Hoangviphb999

    Hoangviphb999 Silverfish

    Messages:
    21
    GitHub:
    Hoangviphb999
    When i do a join, it cause that error on my plugin and the server crashed
    My code:
    $format = str_replace("{hp}", $health, $format);
    $format = str_replace("{ping}", $ping, $format);
    $format = str_replace("{os}", $os, $format);
    $format = str_replace("{cps}", $cps, $format);
    $format = str_replace("{kills}", $kills, $format);
    if(!$player->isDisguised()){
    if(!$player->isVanished()){
    $player->setNameTag($format);
    }else{
    $player->setNameTag("§7(V) ".$format);

    Help please
     
  2. Hoangviphb999

    Hoangviphb999 Silverfish

    Messages:
    21
    GitHub:
    Hoangviphb999
    This error starts on line $format = str_replace("{hp}", $health, $format);
     
  3. Hoangviphb999

    Hoangviphb999 Silverfish

    Messages:
    21
    GitHub:
    Hoangviphb999
    And in CrashDump it said TypeError
     
  4. IvanCraft623

    IvanCraft623 Baby Zombie

    Messages:
    105
    GitHub:
    IvanCraft623
    In the last update of php changed the argument type of the second argument of str_replace, now it can only be string.

    Here are some methods to convert your variable:
    PHP:
    $string strval($value);
    PHP:
    $string = (string)$value;
    PHP:
    $string "$value";
     
  5. IvanCraft623

    IvanCraft623 Baby Zombie

    Messages:
    105
    GitHub:
    IvanCraft623
    So you should use:
    PHP:
    $format str_replace("{hp}""$health"$format);
    :trollface:
     
  6. Hoangviphb999

    Hoangviphb999 Silverfish

    Messages:
    21
    GitHub:
    Hoangviphb999
    Ok
     
  7. Hoangviphb999

    Hoangviphb999 Silverfish

    Messages:
    21
    GitHub:
    Hoangviphb999
    Ok thanks for help, it solved
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.