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

check word in one sentence

Discussion in 'Development' started by Felic, Jun 23, 2021.

  1. Felic

    Felic Spider

    Messages:
    7
    Hello,

    can I somehow make that something is recognized in a sentence? So e.g. you now write "Hello people, what's up?" And now I want to check whether there is an "ello" in there. So the "ello" of Hello. How can I check this so the "ello" check of the whole text?

    (sry my english is bad :c)

    FlxiBoy.
     
  2. Axon

    Axon Zombie

    Messages:
    276
    If I'm not mistaken, you can use strpos to search `ello` in a string
    PHP:
    // The !== operator can be used.  Using != would not work as expected
    if (strpos("Hello world!""ello") === false) {
        echo 
    "The string was not found";
    } else {
        echo 
    "The string was found ";
    }
     
    Agent and NTT like this.
  3. Felic

    Felic Spider

    Messages:
    7
    Thx! I'll try the emoji in a moment, thanks!
     
    Axon likes this.
  4. Axon

    Axon Zombie

    Messages:
    276
    Thanks!
     
    Agent likes this.
  5. Felic

    Felic Spider

    Messages:
    7
    so? if no then is there a video or something? I don't quite understand this: c
     
  6. Felic

    Felic Spider

    Messages:
    7
    Okay, I just did it and I look really cool, thank you!
     
    NTT and Axon like this.
  7. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    PHP:

    if (!strpos("Hello world!""ello")) {
        echo 
    "The string was not found";
    } else {
        echo 
    "The string was found ";
    }
    Could you explain for me the different between these two?
     
  8. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    tested and it behaves the same •-•
     
  9. Axon

    Axon Zombie

    Messages:
    276
    Strpos Returns the position of the first occurrence of a string inside another string, or FALSE if the string is not found.

    My code and your code is basically same I believe. I just kept === false for new users to understand it easily.

    Simply == would not work as expected because the position of the character was the 0th (first) character.
     
    Agent and NTT like 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.