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

Get if a special text is in a file

Comments in 'Plugin Development' started by MyNameIsTriXz, Jan 26, 2016.

  1. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    How?
  2. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    What are you even trying to say? Please be more specific. And titles don't describe everything. Get that fact down.
    PocketKiller likes this.
  3. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    AndrewBit likes this.
  4. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    maybe:

    file_get_contents()

    stristr() || strstr()

    OR

    explode(' ', file_get_contents());

    in_array()


    If you need more help, be more specific.anyway, google can help you
    PocketKiller and MyNameIsTriXz like this.
  5. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    I want to check if a text file, I open with fopen (no, I wont use config), contains a special string how am I doing that?
  6. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Sounds good, can you please show me an example about stristr or strstr? :D
  7. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    pls , i'm busy, do you know that google exists ;)? :p
    PocketKiller likes this.
  8. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    applqpak and Svile like this.
  9. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
  10. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
  11. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    spam?
  12. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    How about not being lazy and look through it?
  13. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    How about realizing that we do a big discussion about one simple code?
  14. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    How about stop spamming.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Ingredients: file_get_contents (copies contents of a file into a string), strpos (checks if a substring exists in a string, and finds its position if exists)

    Steps:
    1. Read the file into a string using file_get_contents().
    2. Check if the "special text" you want to search for exists in the string by using strpos() !== false

    With code:
    PHP:
    $hasString strpos(file_get_contents($file), $specialText) !== false;
    Is that so hard? This is what programming is about. Why make it so absurdly complicated?
    CrazedMiner and MyNameIsTriXz like this.
  16. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Thanks.

Share This Page

Advertisement