1

How can I search a paragraph for one or more sentences using PHP?

hippietrail
  • 15,848
  • 18
  • 99
  • 158
john
  • 535
  • 7
  • 23

3 Answers3

3

Yes. strpos will tell you whether a string exists within a string.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • Well it'll tell you the first occurrence :P `strstr()` will give you a Boolean return, except I hear it is slower. – alex Aug 20 '10 at 05:49
  • @alex `strstr` will return the part of the string starting at the match or `false`. `strpos` will return the starting index or `false`. You have to compare both to `=== false`. Not a big difference, really. :P – deceze Aug 20 '10 at 05:54
  • I should really read the docs before I say something... you're right :) Have a +1 – alex Aug 20 '10 at 06:07
1

Have a look over here, maybe here and here.

phimuemue
  • 34,669
  • 9
  • 84
  • 115
1

Well, you'll probably want to use "preg_match()" if possible (requires knowledge of regular expressions though). "strstr()" works too if you know exactly what you want to find.

NightKev
  • 21
  • 3