How do I see if one string is found within another string?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • googlegroups@budget-edi.co.uk

    How do I see if one string is found within another string?

    Hi, I wonder if anyone can help?

    How do I see if one string is found within another string?
    or how many instances of one string, is found within another.

    ie.

    a="Sheree smells of poo"
    b="smells"

    I'd like a function that would return 1, (for true, or that the word
    smells, if found once)

    PHP is ace. There must be a simple way of doing this. I mean, its got
    loads of useless functions that noones ever going to use. Im sure if
    PHP has a built-in function to convert hebrew, then Im sure it can do
    this. Any ideas?

    Cheers
    Phil.

  • Carl

    #2
    Re: How do I see if one string is found within another string?

    googlegroups@bu dget-edi.co.uk wrote:[color=blue]
    > Hi, I wonder if anyone can help?
    >
    > How do I see if one string is found within another string?
    > or how many instances of one string, is found within another.
    >
    > ie.
    >
    > a="Sheree smells of poo"
    > b="smells"
    >
    > I'd like a function that would return 1, (for true, or that the word
    > smells, if found once)
    >
    > PHP is ace. There must be a simple way of doing this. I mean, its got
    > loads of useless functions that noones ever going to use. Im sure if
    > PHP has a built-in function to convert hebrew, then Im sure it can do
    > this. Any ideas?
    >
    > Cheers
    > Phil.
    >[/color]
    Phil,

    Find the position of the first occurrence of a substring in a string


    Carl.

    Comment

    • Geoff Berrow

      #3
      Re: How do I see if one string is found within another string?

      I noticed that Message-ID:
      <5DbLe.442$k92. 260@newssvr19.n ews.prodigy.com > from Carl contained the
      following:
      [color=blue][color=green]
      >> a="Sheree smells of poo"
      >> b="smells"[/color]
      >
      >http://www.php.net/manual/en/function.strpos.php[/color]

      But be careful of the comparison you do. If the search string is at the
      beginning strpos will return 0, naturally. You want anything other than
      false so you need to do !==false as the comparison.

      --
      Geoff Berrow (put thecat out to email)
      It's only Usenet, no one dies.
      My opinions, not the committee's, mine.
      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

      Comment

      • Chung Leong

        #4
        Re: How do I see if one string is found within another string?

        strstr() or stristr().

        Comment

        • Mladen Gogala

          #5
          Re: How do I see if one string is found within another string?

          On Fri, 12 Aug 2005 17:45:37 -0700, googlegroups wrote:
          [color=blue]
          > How do I see if one string is found within another string?
          > or how many instances of one string, is found within another.[/color]

          strstr(),preg_m atch()

          --


          Comment

          Working...