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

CHecking Item Name

Discussion in 'Development' started by Junkdude, Jan 3, 2017.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    So I'm working on a plugin that checks the item name and then checks for a certian word, this piece of code doesnt work, but doesnt throw any errors. Anyways here:
    PHP:
    if($it->getNamedTag() == $it->getName()."\nWhatEverYouWantToNameThisItem"){
     
  2. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Try this:
    PHP:
    if($item->getName() == "YourItemName") {}
     
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    dawg, then it checks for just "YourItemName", im trying to check it for a certain word, but have other words in the item name
     
  4. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    What do you mean with other words in the Item name? Like this?
    Name1\n
    Word2\n
    Word3

    Or do u have an array with words?
     
    #A6543 and applqpak like this.
  5. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    yes exactly like that
     
  6. applqpak

    applqpak Spider Jockey

    Messages:
    27
    GitHub:
    applqpak
    PHP:
    $name strtolower($item->getName());
    if(
    strpos($name'string') !== false)
    {
      
    //do stuff
    }
     
    Last edited: Jan 3, 2017
    Muqsit likes this.
  7. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Lol
    Than use:
    PHP:
    if($item->getName() == "
    Word1\n
    Word2\n
    Word3
    "
    ) {}
     
    #A6543 likes this.
  8. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    how do i implement this *facepalm*
     
  9. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Do u want to check if a word is in the Item Name????
     
    Muqsit and #A6543 like this.
  10. applqpak

    applqpak Spider Jockey

    Messages:
    27
    GitHub:
    applqpak
    Replace your code with that.
     
  11. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    yes
     
  12. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Than use this:
    PHP:
    $words "Word1\n Word2"//$words = $item->getName();
    $word  "Word1"

    if( strpos$words$word ) !== false ) {
       
    //Word is in the Name!
    }
     
    #A6543 likes this.
  13. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    again, do i just replace this code with that
     
  14. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    What's the problem?
     
    #A6543 likes this.
  15. applqpak

    applqpak Spider Jockey

    Messages:
    27
    GitHub:
    applqpak
    I literally already posted this.
     
    Muqsit and #A6543 like this.
  16. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    No. I tried to post it with more details

    PHP:
    $words $item->getName(); //The item name
    $word  "Word1" //Word u want to search in the Item name

    if( strpos$words$word ) !== false ) { //Checks if the the word in $word is in the item name ($words)
       //Word is in the Name!
    }
     
    #A6543 and applqpak like this.
  17. applqpak

    applqpak Spider Jockey

    Messages:
    27
    GitHub:
    applqpak
    Yes, but the method is the same. Also, if anyone creating a plugin doesn't know what an if/strpos statement does they need to go back to learning basic PHP.
     
  18. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Yes. But I thought he needed more infos/details :)
     
    applqpak likes this.
  19. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    gonne be honest here, i never even studied php, i just looked at plugins and the functions and how they work
     
    applqpak likes this.
  20. applqpak

    applqpak Spider Jockey

    Messages:
    27
    GitHub:
    applqpak
    That's fine - a lot of people do that, but it'll help you a lot in the future if you just go back to the basics and learn PHP properly.
     
    VentroxStudio likes this.
  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.