sohal07
sohal07

Reputation: 482

How to search for a word in file contents?

I am new to php, just got stuck with something could be even simple... Anyway, I want to do some action if the value from the "url" has a word "Success" in it:

$c = file_get_content($url)

Upvotes: 1

Views: 144

Answers (2)

cdtits
cdtits

Reputation: 1128

You may use stripos() for case-insensitive, and strpos() for case-sensitive search.

Upvotes: 0

Blender
Blender

Reputation: 298126

Always search through the PHP documentation:

if (strpos($c, "string") !== false) {
  // "string" is in $c
} else {
  // "string" isn't in $c
}

Upvotes: 3

Related Questions