Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching a string for text 1

Status
Not open for further replies.

jimoblak

Instructor
Oct 23, 2001
3,620
US
I need to find certain text in a string and would appreciate any help on the most efficient way to do this.

I am searching a long text string for the word 'rescanned'. The only way my feeble mind is able to do this now is with explode() and a few lines to sort through the exploded string to find 'rescanned'. Is there an easier way to determine if this word appears in a string?

- - picklefish - -
Why is everyone in this forum responding to me as picklefish?
 
You probably want to look at the strpos() function:
Code:
if (strpos($str,'rescanned') !== FALSE) echo 'Found string';

Ken
 
strpos() is less of a memory hog than strstr(). Use the first.
 
Use the first.

I'm confused. Use the first of what? The first example is strstr()

- - picklefish - -
Why is everyone in this forum responding to me as picklefish?
 
he was referring to the first of the two functions in his preceding sentence. i.e. strpos().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top