Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Replace symbol

Comments in 'Plugin Development' started by ImagicalGamer, Apr 3, 2016.

  1. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    I'm replacing the color names in a config to represent their colors:
    PHP:
    $green "§a";
        
    $aqua "§b";
        
    $red "§c";
        
    $yellow "§e";
        
    $purple "§d";
        
    $bold "§l";
        
    $config = new Config($this->getDataFolder() . "/config.yml"Config::YAML);
        
    $reason str_replace("GREEN"$green"AQUA"$aqua"RED"$red"YELLOW"$yellow"PURPLE"$purple"BOLD"$bold$config->get("Reason"));
    It works but I can only use one color:
    Code:
    Reason: GREEN example
    I can't do:
    Code:
    Reason: GREEN BOLD example
    How can I fix that? Any help/guidance is appreciated!
    btw: I checked HERE using mixed str_replace didn't work for me.
  2. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Try:
    PHP:
    $colour = ['§a''§b''§c'];
    $i = ['GREEN''AQUA''RED'];
    $reason str_replace($i$colour$cfg->get('reason'));
    applqpak and ImagicalGamer like this.
  3. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    PHP:
    $reason str_replace("&""\xc2\xa7"$config->get("reason"));

    //&b  = bold
    applqpak likes this.
  4. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    =D thanks. I feel so stupid now.
    applqpak likes this.
  5. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    YAML Parsing error when using that.
    applqpak likes this.
  6. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    no.
  7. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    Yes, when using & in config it gets a parsing error, I even tested it on a yaml parsing site.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Add double quotes?
  9. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    Tried that, then it won't get the info in the config.

Share This Page

Advertisement